<?php

namespace app\controller;

use app\BaseController;
use app\message;
use app\model\AutoTask;
use app\model\ClueMobile;
use app\model\CluePerson;
use app\model\CluePersonAllocationRecord;
use app\model\OrderDeal;
use app\model\OrderDealChargeback;
use app\model\OrderEnterpriseCertificateBusiness;
use app\model\OrderEnterpriseCertificateRegister;
use app\model\OrderEnterpriseCompany;
use app\model\OrderEnterpriseExchange;
use app\model\OrderLog;
use app\model\OrderOtherCertificateBusiness;
use app\model\OrderPersonCertificateRegister;
use app\model\OrderTransactionRecord;
use app\model\SystemMenuDataPower;
use app\model\SystemOperateLog;
use app\model\UnitInfo;
use app\model\User;
use app\model\WorkPlan;
use app\Request;
use app\model\UserOrganization;
use app\service\Certificate;
use app\service\Clue;
use app\service\CluePersonServer;
use app\service\CustomerPerson;
use app\service\CustomField;
use app\service\Excel;
use app\service\FinanceServer;
use app\service\OrderCertReverseCase;
use app\service\OrderCertTransact;
use app\service\OrderEnterCert;
use app\service\Power;
use app\service\RedisService;
use app\service\System;
use app\stateData;
use app\validate\ClueEnterprise as ClueEnterpriseValidate;
use app\validate\ClueUPersonList;
use GatewayClient\Gateway;
use PhpOffice\PhpSpreadsheet\IOFactory;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;

class FromButton extends BaseController
{
    /**
     * 表单操作按钮
     */

    private $isDel = 1;
    private $isF = 1; //未分配
    private $is_y_f = 2;
    private $isUid = 0;
    private $plan = 1;//跟进计划
    private $tasks = 2;//任务提醒
    private $message_plan_type = 1; //消息表跟进计划分类
    private $message_tasks_type = 7;//消息表任务提醒分类
    private $complete = 1;
    private $page = 1;

    private $exePerson = 1;
    private $exeDh = 1;
    private $exeEnter = 2;
    private $exeHs = 2;
    private $PersonDh = '人才调回';
    private $EnterDh = '企业调回';
    private $PersonFp = '人才分配';
    private $EnterFp = '企业分配';
    private $EnterDel = '企业删除';
    private $PersonDel = '人才删除';
    private $PersonHh = '人才回收';
    private $EnterHh = '企业回收';

    /*************
     * 回收操作
     * @param \app\Request $request
     * @param \app\model\CluePerson $person
     * @param \app\model\CluePersonAllocationRecord $cluePersonAllocationRecord
     * @return false|string
     */
    //回收人才操作
    public function recoveryPersonOp(
        Request                    $request,
        CluePerson                 $person,
        CluePersonAllocationRecord $cluePersonAllocationRecord,
        RedisService               $redisService,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->post('id');
        $uid = $request->post('user_login_id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        try {
            $data = explode(',', $id);

            if (is_array($data)) foreach ($data as $datum) {

                $person->editPersonModel([
                    'id' => $datum,
                    'is_del' => $this->isDel,
                    'is_f' => 0,
                    'f_uid' => 0
                ]);
                //更新缓存
                $redisService->updatePersonData ($person->getIdPersonInfo ($datum),$uid);
                //添加人才生命周期
                $cluePersonAllocationRecord->addPersonAllocationModel($datum, $this->PersonHh, $uid, 1);
                //添加日志
                $systemOperateLogModel->addOperate ($uid,message::$RERSON,$this->PersonHh);
            }
        } catch (\Exception $e) {
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }
        return ReJson(message::$SUCC_CODE, message::$SUCC_RECOVERY);

    }


    //回收企业操作
    public function recoveryEnterOp(
        Request                    $request,
        \app\model\ClueEnterprise  $enterprise,
        CluePersonAllocationRecord $cluePersonAllocationRecord,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->post('id');
        $uid = $request->post('user_login_id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        try {
            $data = explode(',', $id);

            if (is_array($data)) foreach ($data as $datum) {

                $enterprise->editEnterprise([
                    'id' => $datum,
                    'is_del' => $this->isDel,
                    'is_f' => $this->isF,
                    'f_uid' => 0
                ]);

                //添加企业生命周期
                $cluePersonAllocationRecord->addPersonAllocationModel($datum, $this->EnterHh, $uid, 2);
                //添加日志
                $systemOperateLogModel->addOperate ($uid,message::$ENTER,$this->EnterHh);
            }
        } catch (\Exception $e) {
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }
        return ReJson(message::$SUCC_CODE, message::$SUCC_RECOVERY);
    }



    /*******************************************************
     * 调回操作
     */

    //调回人才
    public function recallPerson(
        Request                    $request,
        CluePerson                 $person,
        CluePersonAllocationRecord $personAllocationRecord,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->post('id');
        $uid = $request->post('user_login_id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        try {
            $data = explode(',', $id);

            if (is_array($data)) foreach ($data as $datum) {

                $person->editPersonModel([
                    'id' => $datum,
                    'is_f' => $this->isF,
                    'f_uid' => $this->isUid,
                    'allocation_date' => ''
                ]);

                //更新缓存
                $idData = $person->getIdPersonInfo ($datum);
                $redisService->updatePersonData ($idData,$uid);

                //记录该人才生命周期
                $personAllocationRecord->addPersonAllocationModel($datum, $this->PersonDh, $uid, 1);
                //添加日志
                $systemOperateLogModel->addOperate ($uid,message::$RERSON,$this->PersonDh);
            }
        } catch (\Exception $e) {
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }
        return ReJson(message::$SUCC_CODE, message::$SUCC_RECALL);
    }


    //调回企业
    public function recallEnter(
        Request                    $request,
        \app\model\ClueEnterprise  $enterprise,
        CluePersonAllocationRecord $allocationRecord,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->post('id');
        $uid = $request->post('user_login_id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        try {
            $data = explode(',', $id);

            if (is_array($data)) foreach ($data as $datum) {

                $enterprise->editEnterprise([
                    'id' => $datum,
                    'is_f' => $this->isF,
                    'f_uid' => $this->isUid,
                    'allocation_date' => ''
                ]);

                //记录企业生命周期
                $allocationRecord->addPersonAllocationModel($datum, $this->EnterDh, $uid, 2);
            }
            //添加日志
            $systemOperateLogModel->addOperate ($uid,message::$ENTER,$this->EnterDh);
        } catch (\Exception $e) {
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }
        return ReJson(message::$SUCC_CODE, message::$SUCC_RECALL);
    }



    /***********************************************************
     * 分配操作
     */
    //分配人才
    public function allocationPerson(
        Request                    $request,
        CluePerson                 $person,
        CluePersonAllocationRecord $personAllocationRecord,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->post('id');
        $f_id = $request->post('f_id');
        $uid = $request->post('user_login_id');
        if (empty($id) || empty($f_id)) {
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }

        try {
            $data = explode(',', $id);
            if (is_array($data)) foreach ($data as $datum) {
                $person->editPersonModel([
                    'id' => $datum,
                    'f_uid' => $f_id,
                    'is_f' => $this->is_y_f,
                    'is_del' => 0,
                    'allocation_date' => date('Y-m-d H:i:s')  //分配时间
                ]);

                //更新缓存
                $idData = $person->getIdPersonInfo ($datum);
                $redisService->updatePersonData ($idData,$uid);

                //记录该人才生命周期
                $personAllocationRecord->addPersonAllocationModel($datum, $this->PersonFp, $uid);
                //添加日志
                $systemOperateLogModel->addOperate ($uid,message::$RERSON,message::$SUCC_PERSON_ALLOCATION);
            }
//            exit;
        } catch (\Exception $e) {
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_ALLOCATION_PERSON);
    }


    //分配企业
    public function allocationEnter(
        Request                    $request,
        \app\model\ClueEnterprise  $enterprise,
        CluePersonAllocationRecord $cluePersonAllocationRecord,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->post('id');
        $f_id = $request->post('f_id');
        $uid = $request->post('user_login_id');

        if (empty($id) || empty($f_id)) {
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }

        try {
            $data = explode(',', $id);

            if (is_array($data)) foreach ($data as $datum) {

                $enterprise->editEnterprise([
                    'id' => $datum,
                    'f_uid' => $f_id,
                    'is_f' => $this->is_y_f,
                    'is_del' => 0,
                    'allocation_date' => date('Y-m-d H:i:s')  //分配时间
                ]);

                //记录企业生命周期
                $cluePersonAllocationRecord->addPersonAllocationModel($datum, $this->EnterFp, $uid, 2);
                //添加日志
                $systemOperateLogModel->addOperate ($uid,message::$ENTER,message::$SUCC_PERSON_ALLOCATION);
            }
        } catch (\Exception $e) {
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_ALLOCATION_ENTER);
    }


    /******************************************************************************************
     * 一键分配人才
     */

    public function autoAllocationPerson(
        Request                          $request,
        Power                            $power,
        CluePerson                       $person,
        \app\service\Clue                $clue,
        CluePersonServer                 $cluePersonServer,
        System                           $system,
        \app\service\Order               $order,
        \app\service\SystemMenuDataPower $dataPower,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel,
        CluePersonAllocationRecord $personAllocationRecord,
        User $user
    ){
        $uid = $request->post('user_login_id');
        $param = $request->post();
        //获取当前登陆人昵称
        $nickname = $user->getIdNickName ($uid);

        //获取要分配数据条数
        $num = $request->post ('data_num');
        $uidArr = explode (',',$request->post ('uid_str'));

        if (empty($num) || empty($uidArr)) return ReJson (message::$ERROR_CODE,message::$ERR_PARAM_EMPTY);

        //判断分配值是否是整数
        $allocationNum = $num / count ($uidArr);
        if (!is_int ($allocationNum)){
            return ReJson (message::$ERROR_CODE,message::$ERR_PARAM_ALLOCATION);
        }

        //参数验证
        $validate = new ClueUPersonList();
        if (!$validate->check($param)) {
            return ReJson(message::$ERROR_CODE, $validate->getError(), []);
        }

        //判断参数是否有值
        $flag = false;
        $key_arr = [
            'aliasId',
            'page',
            'pageNum',
            'user_login_id',
        ];
        foreach ($param as $key => $item) {
            if (in_array($key, $key_arr)) {
                continue;
            }
            if ($item) {
                $flag = true;
                break;
            }
        }

        //将每个参数整合为条件
        $person_ids = $cluePersonServer->spliceWhere($param);

        //根据条件查询用户范围
        $userData = $power->getUserDataRange($uid);

        $data = $dataPower->getOpenSeaPower($uid);

        //用户person_ID
        $uid_person_ids = $person->newGetRangeDataPersonId($userData,$data,$param);
        $person_ids = $this->handlePersonIds($uid_person_ids, $person_ids, $flag);
        //根据用户范围查询人才数据
        $listId = $person->newIdDataModel($person_ids);

        //循环分配
        $k = 0;//总数据从0开始
        $ids = '';
        for ($j = 0, $jMax = $allocationNum; $j < $jMax; $j++) {
            for ($i = 0, $iMax = count ($uidArr); $i < $iMax; $i++) {
                //大于总分配数值跳出
                if ($k >= $num) {
                    break;
                }
                $ids .= $listId[$k].',';
                //开始分配
                $person->editPersonIdModel ($listId[$k],['f_uid'=>$uidArr[$i],'is_f'=>2,'allocation_date'=>date('Y-m-d H:i:s')]);
                //更新缓存
                $idData = $person->getIdPersonInfo ($listId[$k]);
                $redisService->updatePersonData ($idData,$uid);
                //记录该人才生命周期
                $personAllocationRecord->addPersonAllocationModel($listId[$k], $this->PersonFp, $uid);
                $k++;
            }
        }
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$RERSON,message::$SUCC_PERSON_YJ_ALLOCATION.'人才ID:'.$ids);
        return ReJson (message::$SUCC_CODE,message::$SUCC_ALLOCATION_PERSON);
    }


    /*********************************************************************************************************************
     * 一键分配所有企业
     */
    public function autoAllocationEnter(
        Request                     $request,
        \app\model\ClueEnterprise   $cent,
        User                        $user,
        Power                       $power,
        SystemMenuDataPower         $dataPower,
        \app\service\User           $userService,
        Certificate                 $certificate,
        \app\service\Order          $orderSer,
        \app\service\ClueEnterprise $clueEnterprise,
        \app\service\Clue $clueSer,
        CustomField $customField,
        \app\service\SystemMenuDataPower $dataPowerServer,
        SystemOperateLog $systemOperateLogModel,
        CluePersonAllocationRecord $cluePersonAllocationRecord
    ){

        $uid = $request->post('user_login_id');
        //获取当前登陆人昵称
        $nickname = $user->getIdNickName ($uid);
        //查询电销部还是网销部
        $type = $request->post('type') ?: 1;

        $param = $request->post();

        //获取要分配数据条数
        $num = $request->post ('data_num');
        $uidArr = explode (',',$request->post ('uid_str'));

        if (empty($num) || empty($uidArr)) return ReJson (message::$ERROR_CODE,message::$ERR_PARAM_EMPTY);

        //判断分配值是否是整数
        $allocationNum = $num / count ($uidArr);
        if (!is_int ($allocationNum)){
            return ReJson (message::$ERROR_CODE,message::$ERR_PARAM_ALLOCATION);
        }

//        $validate = new ClueEnterpriseValidate();
//        if (!$validate->check($param)) {
//            return ReJson(message::$ERROR_CODE, $validate->getError(), []);
//        }
        $flag = flagStatus($param);
        $ids = $clueEnterprise->spliceWhere($param);
        $ids = !$ids ? [0] : $ids;

        //查询用户数据范围
        $range = $power->getUserDataRange($uid);

        //根据条件查询用户范围
        $data = $dataPowerServer->getOpenSeaPower($request->param('user_login_id'));
        $uid_ids = $cent->getManageListIds($range, $type,$data,$param);

        $ids = handlePersonIds($uid_ids, $ids, $flag);

        //企业数据
        $resultId = $cent->getManageListModel($range, '',$type, '',$ids);
        $ids = '';
        //循环分配
        $k = 0;//总数据从0开始
        for ($j = 0, $jMax = $allocationNum; $j < $jMax; $j++) {
            for ($i = 0, $iMax = count ($uidArr); $i < $iMax; $i++) {
                //大于总分配数值跳出
                if ($k >= $num) {
                    break;
                }

                $ids .= $resultId[$k]['id'].',';
                //开始分配
                $cent->editEnterprise (['id'=>$resultId[$k]['id'],'f_uid'=>$uidArr[$i],'is_f'=>2,'allocation_date'=>date('Y-m-d H:i:s')]);

                //记录该企业生命周期
                $cluePersonAllocationRecord->addPersonAllocationModel($resultId[$k]['id'], $this->EnterFp, $uid,2);
                $k++;
            }
        }
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$ENTER,message::$SUCC_PERSON_YJ_ALLOCATION.'企业ID：'.$ids);
        return ReJson (message::$SUCC_CODE,message::$SUCC_ALLOCATION_PERSON);

    }


    /*************************************************************************
     * 删除操作
     */
    //删除人才
    public function delPerson(
        Request                        $request,
        CluePerson                     $person,
        OrderPersonCertificateRegister $certificateRegister,
        CluePersonAllocationRecord     $allocationRecord,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->post('id');
        $uid = $request->post('user_login_id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        try {
            $data = explode(',', $id);
            $personData = [];
            if (is_array($data)) foreach ($data as $datum) {
                //删除每个人才
                $personData = $person->getIdPersonInfo($datum);
                //是否满足删除条件
                if (!empty($personData)) {
                    $personCer = $certificateRegister->getPersonIdCardOrderModel($personData['person_id_card']);
                    if (!empty($personCer)) {
                        return ReJson(message::$ERROR_CODE, message::$PERSON_DELETE_ORDER_EXIST);
                    }
                }

                $person->delId($datum);
                //删除缓存
                $redisService->delPersonData ($datum);
                //记录企业生命周期
                $allocationRecord->addPersonAllocationModel($id, $this->PersonDel, $uid, 1);
                //添加日志
                $systemOperateLogModel->addOperate ($uid,message::$RERSON,message::$SUCC_PERSON_DELETE);
            }
        } catch (\Exception $e) {
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_DATELE_DATA);
    }

    //删除企业
    public function delEnter()
    {

        //controller  ClueEnterPrise  delEnterprice
    }


    /******************************************************************************
     * 导出
     * @param \app\service\Excel $excel
     * @param \app\Request $request
     * @param \app\model\WorkPlan $plan
     * @param \app\service\Power $power
     * @return false|string|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    //跟进计划导出
    public function planExportExcel(
        Excel    $excel,
        Request  $request,
        WorkPlan $plan,
        Power    $power,
        SystemOperateLog $systemOperateLogModel
    ){
        $custom_name = $request->get('custom_name') ?: '';
        $start_date = $request->get('start_date') . '00:00:00'; //开始时间
        $end_date = $request->get('end_date') . '23:59:58'; //结束时间
        $uid = $request->get ('user_login_id');

        if (!empty($request->get('complete'))) {
            $complete = $request->get('complete');
        } else {
            $complete = '1,2';
        }

        if (empty($start_date) || empty($end_date)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        $userIn = $power->getUserDataRange($request->param('user_login_id'));

        $data = $plan->exportDataModel($this->plan, $userIn, $custom_name, $start_date, $end_date, $complete);

        $header = [
            ['s_cell' => 'id', 's_value' => 'id', 's_width' => 10],
            ['s_cell' => 'custom_name', 's_value' => '客户名称', 's_width' => 10],
            ['s_cell' => 'plan_date', 's_value' => '计划执行时间', 's_width' => 10],
            ['s_cell' => 'plan_content', 's_value' => '沟通内容', 's_width' => 10],
            ['s_cell' => 'is_complete', 's_value' => '状态', 's_width' => 10],
            ['s_cell' => 'abutment', 's_value' => '对接人', 's_width' => 10],
            ['s_cell' => 'u_mobile', 's_value' => '联系电话', 's_width' => 10],
            ['s_cell' => 'create_uid', 's_value' => '创建人', 's_width' => 10],
            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
        ];

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$GJJH,message::$EXPORT);
        $excel->outExcelStart($data, $header, '跟进计划导出');
    }

    //任务提醒导出
    public function tasksExportExcel(
        Excel    $excel,
        Request  $request,
        WorkPlan $plan,
        Power    $power,
        SystemOperateLog $systemOperateLogModel
    ){
        $custom_name = $request->get('custom_name') ?: '';
        $start_date = $request->get('start_date') . "00:00:00"; //开始时间
        $end_date = $request->get('end_date') . "23:59:58"; //结束时间
        $uid = $request->get ('user_login_id');

        if (!empty($request->get('complete'))) {
            $complete = $request->get('complete');
        } else {
            $complete = '1,2';
        }

        if (empty($start_date) || empty($end_date)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);


        $userIn = $power->getUserDataRange($request->param('user_login_id'));

        $data = $plan->exportDataModel($this->tasks, $userIn, $custom_name, $start_date, $end_date, $complete);
        $header = [
            ['s_cell' => 'id', 's_value' => 'id', 's_width' => 10],
            ['s_cell' => 'custom_name', 's_value' => '客户名称', 's_width' => 10],
            ['s_cell' => 'plan_date', 's_value' => '提醒时间', 's_width' => 10],
            ['s_cell' => 'plan_content', 's_value' => '提醒内容', 's_width' => 10],
            ['s_cell' => 'is_complete', 's_value' => '状态', 's_width' => 10],
            ['s_cell' => 'create_uid', 's_value' => '创建人', 's_width' => 10],
            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
        ];

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$RWTX,message::$EXPORT);
        $excel->outExcelStart($data, $header, '任务提醒导出');
    }

    //人才导出
    public function personExportExcel(
        Request    $request,
        Excel      $excel,
        CluePerson $person,
        Clue       $clue,
        CluePersonServer  $cluePersonServer,
        Power $power,
        \app\service\Order          $orderSer,
        CustomerPerson  $customerPerson,
        \app\service\SystemMenuDataPower $dataPower,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel
    ){

        $id = $request->param('id');
        $uid = $request->param('user_login_id');//登陆数据
        $all = $request->param('all'); //是否导出全部数据
        $param = $request->param();
        $uid = $request->get('user_login_id');
        $aliasId = $request->get('aliasId');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if ($all){
            //参数验证
            $validate = new ClueUPersonList();
            if (!$validate->check($param)) {
                return ReJson(message::$ERROR_CODE, $validate->getError(), []);
            }

            $flag = flagStatus($param);
            $person_ids = $customerPerson->spliceWhere($param);

            //根据条件查询用户范围
            $userData = $power->getUserDataRange($uid);
            $data = $dataPower->getOpenSeaPower($uid);

            //用户person_ID
            $uid_person_ids = $person->newGetRangeDataPersonId($userData,$data,$param);
            $person_ids = $this->handlePersonIds($uid_person_ids, $person_ids, $flag);

            //根据用户范围查询人才数据
            if (isset($param['source'])){ //客户管理导出
                $dataId = $person->newGetRangeAllData($userData, $person_ids);
            }else{
                $dataId = $person_ids;
            }
        }else{
            $dataId = $person->getIdRandData($id);
        }
        //查询缓存是否与数据库ID一致，不一致同步到redis
        $data = $redisService->getPersonDataReSet ($dataId,$uid);

        //处理人才 status
        foreach ($data as &$datum) {
            $datum['status'] = stateData::$_person_status[$datum['status']];
            $datum['is_zd'] = stateData::$_customers[$datum['is_zd']];
        }

        //字段权限
        $fieldListTree = $power->getUserFieldPower($aliasId, $uid);

        $header = [];
        if (isset($param['source'])) { //客户管理导出 删除订单为0的数据
            //删除订单为0的数据
            $data = $orderSer->delOrderEmpty($data);
            foreach ($fieldListTree as $value) {
                $header[] = ['s_cell' => $value['alias_field_id'], 's_value' => $value['name'], 's_width' => 10];
            }
//            $header = [
//                ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
//                ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
//                ['s_cell' => 'person_id_card', 's_value' => '身份证号', 's_width' => 10],
//                ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
//                ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
//                ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
//                ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
//                ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
//                ['s_cell' => 'allocation_date', 's_value' => '分配时间', 's_width' => 10],
//                ['s_cell' => 'username', 's_value' => '负责人', 's_width' => 10],
//                ['s_cell' => 'order_goods_number', 's_value' => '订单', 's_width' => 10],//个数【个人/所有】
//            ];
        } else {
            foreach ($fieldListTree as $value) {
                $header[] = ['s_cell' => $value['alias_field_id'], 's_value' => $value['name'], 's_width' => 10];
            }
//            $header = [
//                ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
//                ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
//                ['s_cell' => 'is_zd', 's_value' => '重点客户', 's_width' => 10],
//                ['s_cell' => 'zd_date', 's_value' => '设置时间', 's_width' => 10],
//
//                ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
//                ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
//                ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
//                ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
//                ['s_cell' => 'certificate_period_of_validity', 's_value' => '证书到期时间', 's_width' => 10],
//                ['s_cell' => 'certificate_b', 's_value' => 'B证', 's_width' => 10],
//                ['s_cell' => 'certificate_b_period_of_validity', 's_value' => 'B证到期时间', 's_width' => 10],
//                ['s_cell' => 'certificate_log_off', 's_value' => '证书注销时间', 's_width' => 10],
//                ['s_cell' => 'other_certificate', 's_value' => '其他证书', 's_width' => 10],
//                ['s_cell' => 'intention', 's_value' => '意向结果', 's_width' => 10],
//                ['s_cell' => 'call', 's_value' => '呼叫结果', 's_width' => 10],
//                ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
//                ['s_cell' => 'next_communicate_date', 's_value' => '下次沟通时间', 's_width' => 10],
//                ['s_cell' => 'social_security', 's_value' => '社保', 's_width' => 10],
//                ['s_cell' => 'project', 's_value' => '项目', 's_width' => 10],
//                ['s_cell' => 'is_wx', 's_value' => '是否添加企业微信', 's_width' => 10],
//                ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
//                ['s_cell' => 'allocation_date', 's_value' => '分配时间', 's_width' => 10],
//                ['s_cell' => 'become_due', 's_value' => '他人合作到期时间', 's_width' => 10],
//                ['s_cell' => 'username', 's_value' => '负责人', 's_width' => 10],
//                ['s_cell' => 'order_goods_number', 's_value' => '订单个数', 's_width' => 10],//个数【个人/所有】
//                ['s_cell' => 'status', 's_value' => '订单状态', 's_width' => 10],
//
////                ['s_cell' => 'mobile', 's_value' => '联系电话', 's_width' => 10],
////                ['s_cell' => 'communicate_content', 's_value' => '沟通记录', 's_width' => 10],
////                ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
//                ['s_cell' => 'is_f', 's_value' => '是否分配', 's_width' => 10],
//                ['s_cell' => 'person_id_card', 's_value' => '身份证号', 's_width' => 10],
//                ['s_cell' => 'mobile', 's_value' => '联系电话', 's_width' => 10],
//                ['s_cell' => 'communicate_content', 's_value' => '沟通记录', 's_width' => 10],
//                ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
//                ['s_cell' => 'is_f', 's_value' => '是否分配', 's_width' => 10],
//            ];
        }
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$RERSON,message::$EXPORT);
        $excel->outExcelStart($data, $header, '人才库导出');
    }

    //回收站人才导出
    public function personHszExportExcel(
        Request    $request,
        Excel      $excel,
        CluePerson $person,
        CluePersonServer  $cluePersonServer,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel
    ){

        $id = $request->param('id');
        $uid = $request->param('user_login_id');
        $all = $request->param ('all');
        $param = $request->get();
        $uid = $request->get ('user_login_id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if ($all){
            //参数验证
            $validate = new ClueUPersonList();
            if (!$validate->check($param)) {
                return ReJson(message::$ERROR_CODE, $validate->getError(), []);
            }
            $flag = flagStatus($param);
            //将每个参数整合为条件
            $person_ids = $cluePersonServer->spliceWhere($param);
            $person_ids = !$person_ids ? [0] : $person_ids;

            $all_person_ids = $person->getDelEqRecycleIds();
            $ids = handlePersonIds($all_person_ids, $person_ids, $flag);

            $dataId = $person->getDelEqRecycleAllModel($ids);
        }else{
            $dataId = $person->getIdRandData($id);
        }
        $data = $redisService->getPersonDataReSet ($dataId,$uid);

        //处理人才 status
        foreach ($data as &$datum) {
            if (!$datum){
                continue;
            }
            $datum['status'] = stateData::$_person_status[$datum['status']];
            $datum['is_zd'] = stateData::$_customers[$datum['is_zd']];
        }

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'is_zd', 's_value' => '重点客户', 's_width' => 10],
            ['s_cell' => 'zd_date', 's_value' => '重点客户设置时间', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'person_id_card', 's_value' => '身份证号', 's_width' => 10],
            ['s_cell' => 'mobile', 's_value' => '联系电话', 's_width' => 10],
            ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
            ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
            ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
            ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
            ['s_cell' => 'project', 's_value' => '项目', 's_width' => 10],
            ['s_cell' => 'certificate_period_of_validity', 's_value' => '证书到期时间', 's_width' => 10],
            ['s_cell' => 'certificate_b', 's_value' => 'B证', 's_width' => 10],
            ['s_cell' => 'certificate_b_period_of_validity', 's_value' => 'B证到期时间', 's_width' => 10],
            ['s_cell' => 'social_security', 's_value' => '社保', 's_width' => 10],
            ['s_cell' => 'other_certificate', 's_value' => '其他证书', 's_width' => 10],
            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
            ['s_cell' => 'allocation_date', 's_value' => '分配时间', 's_width' => 10],
            ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
            ['s_cell' => 'communicate_content', 's_value' => '沟通记录', 's_width' => 10],
//            ['s_cell' => 'next_communicate_date', 's_value' => '下次沟通时间', 's_width' => 10],
            ['s_cell' => 'certificate_log_off', 's_value' => '证书注销时间', 's_width' => 10],
            ['s_cell' => 'is_wx', 's_value' => '是否添加企业微信', 's_width' => 10],
            ['s_cell' => 'become_due', 's_value' => '他人合作到期时间', 's_width' => 10],
            ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
//            ['s_cell'=>'username','s_value'=>'负责人','s_width'=>10],
            ['s_cell' => 'order_goods_number', 's_value' => '个数【个人/所有】', 's_width' => 10],//个数【个人/所有】
            ['s_cell' => 'status', 's_value' => '订单状态', 's_width' => 10],
        ];

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$RECYCLE,'回收站人才库导出');
        $excel->outExcelStart($data, $header, '回收站人才库导出');
    }

    //企业导出
    public function enterExportExcel(
        Request                   $request,
        Excel                     $excel,
        \app\model\ClueEnterprise $enterprise,
        Clue                      $clue,
        Certificate               $certificate,
        \app\service\Order        $orderSer,
        \app\model\ClueEnterprise   $cent,
        User                        $user,
        Power                       $power,
        SystemMenuDataPower         $dataPower,
        \app\service\User           $userService,
        \app\service\ClueEnterprise $clueEnterprise,
        \app\service\Clue $clueSer,
        CustomField $customField,
        \app\service\CustomerEnterPriseList $customerEnterPriseList,
        \app\service\SystemMenuDataPower $dataPowerService,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->param('id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        $data = $certificate->arrMobile($enterprise->getIdRandDataModel($id));
        $uid = $request->get('user_login_id');
        $all = $request->get ('all');
        $type = $request->get('type') ?: 1; //1注册企业  2合作伙伴
        $param = $request->get ();

        if ($all){
//            $validate = new ClueEnterpriseValidate();
//            if (!$validate->check($param)) {
//                return ReJson(message::$ERROR_CODE, $validate->getError(), []);
//            }
            $flag = flagStatus($param);
            $ids = $clueEnterprise->spliceWhere($param);
            $ids = !$ids ? [0] : $ids;

            //查询用户数据范围
            $range = $power->getUserDataRange($uid);
            $data = $dataPowerService->getOpenSeaPower($uid);
            $uid_ids = $cent->getManageListIds($range, $type,$data,$param);

            $ids = handlePersonIds($uid_ids, $ids, $flag);

            $resultId = $cent->getManageListAllModel($range, $type, $ids);

            //获取企业订单个数
            $result = $redisService->getEnterData ($resultId,$uid);

            //筛选已合作 未合作
            if (isset($param['status'])){
                if ($param['status'] == 1 || $param['status'] == 2){
                    foreach ($result as $ak => $item) {
                        if ($item['status']['id'] != $param['status']){
                            unset($result[$ak]);
                        }
                    }
                }
            }

            $data = array_values ($result);
            if (isset($param['source'])){ //客户管理导出
                //删除订单为0的数据
                $data = $orderSer->delOrderEmpty($result);

                $filename = '企业管理导出';
                $header = [
                    ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
                    ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
                    ['s_cell' => 'contacts', 's_value' => '联系人', 's_width' => 10],
                    ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
                    ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
                    ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
                    ['s_cell' => 'qualifications_type', 's_value' => '资质类别', 's_width' => 10],
                    ['s_cell' => 'secure_expire_date', 's_value' => '安全到期时间', 's_width' => 10],
                    ['s_cell' => 'register_price', 's_value' => '注册资金', 's_width' => 10],
                    ['s_cell' => 'f_uid', 's_value' => '负责人', 's_width' => 10],
                    ['s_cell' => 'order_goods_number', 's_value' => '订单个数', 's_width' => 10],
                ];

            }else{
                if ($type == 1) {
                    $filename = '注册企业导出';
                    $header = [
                        ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
                        ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
                        ['s_cell' => 'name', 's_value' => '联系人', 's_width' => 10],
                        ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
                        ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
                        ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
                        ['s_cell' => 'qualifications_type', 's_value' => '资质类别', 's_width' => 10],
                        ['s_cell' => 'secure_expire_date', 's_value' => '安全到期时间', 's_width' => 10],
                        ['s_cell' => 'intention', 's_value' => '意向结果', 's_width' => 10],
                        ['s_cell' => 'call', 's_value' => '呼叫结果', 's_width' => 10],
                        ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
                        ['s_cell' => 'communicate_next','s_value'=>'下次沟通时间','s_width'=>10],
                        ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
                        ['s_cell' => 'allocation_date', 's_value' => '分配时间', 's_width' => 10],
                        ['s_cell' => 'f_uid', 's_value' => '负责人', 's_width' => 10],
                        ['s_cell' => 'order_goods_number', 's_value' => '订单个数', 's_width' => 10],
                        ['s_cell' => 'status', 's_value' => '合作状态', 's_width' => 10],
                    ];
                } else {
                    $filename = '合作伙伴导出';
                    $header = [
                        ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
                        ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
                        ['s_cell' => 'name', 's_value' => '联系人', 's_width' => 10],
                        ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
                        ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
                        ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
                        ['s_cell' => 'qualifications_type', 's_value' => '主营业务', 's_width' => 10],
                        ['s_cell' => 'intention', 's_value' => '意向结果', 's_width' => 10],
                        ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
                        ['s_cell' => 'communicate_next','s_value'=>'下次沟通时间','s_width'=>10],
                        ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
                        ['s_cell' => 'allocation_date', 's_value' => '分配时间', 's_width' => 10],
                        ['s_cell' => 'call', 's_value' => '呼叫结果', 's_width' => 10],
                        ['s_cell' => 'f_uid', 's_value' => '负责人', 's_width' => 10],
                        ['s_cell' => 'order_goods_number', 's_value' => '订单个数', 's_width' => 10],
                        ['s_cell' => 'status', 's_value' => '合作状态', 's_width' => 10],
                        ['s_cell' => 'is_f', 's_value' => '是否分配', 's_width' => 10],
                    ];
                }
            }
        }else{

            $data = $clue->enterData($orderSer->getEnterOrderCountNum($data, $uid), $uid);

            if ($type == 1) {
                $filename = '注册企业导出';
                $header = [
                    ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
                    ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
                    ['s_cell' => 'name', 's_value' => '联系人', 's_width' => 10],
                    ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
                    ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
                    ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
                    ['s_cell' => 'qualifications_type', 's_value' => '资质类别', 's_width' => 10],
                    ['s_cell' => 'secure_expire_date', 's_value' => '安全到期时间', 's_width' => 10],
                    ['s_cell' => 'intention', 's_value' => '意向结果', 's_width' => 10],
                    ['s_cell' => 'call', 's_value' => '呼叫结果', 's_width' => 10],
                    ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
                    ['s_cell' => 'communicate_next','s_value'=>'下次沟通时间','s_width'=>10],
                    ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
                    ['s_cell' => 'allocation_date', 's_value' => '分配时间', 's_width' => 10],
                    ['s_cell' => 'f_uid', 's_value' => '负责人', 's_width' => 10],
                    ['s_cell' => 'order_goods_number', 's_value' => '订单个数', 's_width' => 10],
                    ['s_cell' => 'status', 's_value' => '合作状态', 's_width' => 10],
                ];
            } else {
                $filename = '合作伙伴导出';
                $header = [
                    ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
                    ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
                    ['s_cell' => 'name', 's_value' => '联系人', 's_width' => 10],
                    ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
                    ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
                    ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
                    ['s_cell' => 'qualifications_type', 's_value' => '主营业务', 's_width' => 10],
                    ['s_cell' => 'intention', 's_value' => '意向结果', 's_width' => 10],
                    ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
                    ['s_cell' => 'communicate_next','s_value'=>'下次沟通时间','s_width'=>10],
                    ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
                    ['s_cell' => 'allocation_date', 's_value' => '分配时间', 's_width' => 10],
                    ['s_cell' => 'call', 's_value' => '呼叫结果', 's_width' => 10],
                    ['s_cell' => 'f_uid', 's_value' => '负责人', 's_width' => 10],
                    ['s_cell' => 'order_goods_number', 's_value' => '订单个数', 's_width' => 10],
                    ['s_cell' => 'status', 's_value' => '合作状态', 's_width' => 10],

    //                ['s_cell' => 'enterprise_type', 's_value' => '企业类型', 's_width' => 10],
    //                ['s_cell' => 'mobile', 's_value' => '联系电话', 's_width' => 10],
    //                ['s_cell' => 'secure_expire_date', 's_value' => '安全到期时间', 's_width' => 10],
    //                ['s_cell' => 'register_price', 's_value' => '注册资金', 's_width' => 10],
    //                ['s_cell' => 'communicate_content', 's_value' => '沟通记录', 's_width' => 10],
    //                ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
                    ['s_cell' => 'is_f', 's_value' => '是否分配', 's_width' => 10],
                ];
            }
        }

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$ENTER,message::$EXPORT);
        $excel->outExcelStart($data, $header, $filename);
    }

    //回收站企业导出
    public function enterHhzExportExcel(
        Request                   $request,
        Excel                     $excel,
        \app\model\ClueEnterprise $enterprise,
        Clue                      $clue,
        Certificate               $certificate,
        \app\service\Order        $orderSer,
        \app\service\ClueEnterprise $clueEnterprise,
        \app\service\Clue           $clueSer,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->param('id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        $data = $certificate->arrMobile($enterprise->getIdRandDataModel($id));
        $uid = $request->get('user_login_id');
        $type = $request->get('type') ?: 1; //1注册企业  2合作伙伴
        $all = $request->get ('all');
        $param = $request->get ();
        if ($type == 1) {
            $filename = '注册企业导出';
        } else {
            $filename = '合作伙伴导出';
        }

        if ($all){
            $flag = flagStatus($param);
            $ids = $clueEnterprise->spliceWhere($param);
            $ids = !$ids ? [0] : $ids;
            $all_ids = $enterprise->getDelEqRecycleIds($type);
            $ids = handlePersonIds($all_ids, $ids, $flag);

            $data = $clueSer->enterData($orderSer->getEnterOrderCountNum($certificate->arrMobile($enterprise->getDelEqRecycleAllModel($type,$ids)), $uid), $uid);
        }else{
            $data = $clue->enterData($orderSer->getEnterOrderCountNum($data, $uid), $uid);
        }
        if ($type == 1) {
            $header = [
                ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
                ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
                ['s_cell' => 'name', 's_value' => '联系人', 's_width' => 10],
                ['s_cell' => 'mobile', 's_value' => '联系电话', 's_width' => 10],
                ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
                ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
                ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
                ['s_cell' => 'qualifications_type', 's_value' => '资质类别', 's_width' => 10],
                ['s_cell' => 'secure_expire_date', 's_value' => '安全到期时间', 's_width' => 10],
                ['s_cell' => 'register_price', 's_value' => '注册资金', 's_width' => 10],
                ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
                ['s_cell' => 'f_date', 's_value' => '分配时间', 's_width' => 10],
                ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
                ['s_cell' => 'communicate_content', 's_value' => '沟通记录', 's_width' => 10],
//                ['s_cell'=>'communicate_next','s_value'=>'下次沟通时间','s_width'=>10],
                ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
                ['s_cell' => 'intention', 's_value' => '意向结果', 's_width' => 10],
                ['s_cell' => 'call', 's_value' => '呼叫结果', 's_width' => 10],
                ['s_cell' => 'order_goods_number', 's_value' => '订单个数【个人/所有】', 's_width' => 10],
                ['s_cell' => 'order_status', 's_value' => '合作状态', 's_width' => 10],
            ];
        } else {
            $header = [
                ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
                ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
                ['s_cell' => 'enterprise_type', 's_value' => '企业类型', 's_width' => 10],
                ['s_cell' => 'name', 's_value' => '联系人', 's_width' => 10],
                ['s_cell' => 'mobile', 's_value' => '联系电话', 's_width' => 10],
                ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
                ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
                ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
                ['s_cell' => 'qualifications_type', 's_value' => '资质类别', 's_width' => 10],
                ['s_cell' => 'secure_expire_date', 's_value' => '安全到期时间', 's_width' => 10],
                ['s_cell' => 'register_price', 's_value' => '注册资金', 's_width' => 10],
                ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
                ['s_cell' => 'f_date', 's_value' => '分配时间', 's_width' => 10],
                ['s_cell' => 'communicate_date', 's_value' => '最新沟通时间', 's_width' => 10],
                ['s_cell' => 'communicate_content', 's_value' => '沟通记录', 's_width' => 10],
//                ['s_cell'=>'communicate_next','s_value'=>'下次沟通时间','s_width'=>10],
                ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
                ['s_cell' => 'intention', 's_value' => '意向结果', 's_width' => 10],
                ['s_cell' => 'call', 's_value' => '呼叫结果', 's_width' => 10],
                ['s_cell' => 'order_goods_number', 's_value' => '订单个数【个人/所有】', 's_width' => 10],
                ['s_cell' => 'order_status', 's_value' => '合作状态', 's_width' => 10],
            ];
        }
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$RECYCLE,$filename);
        $excel->outExcelStart($data, $header, $filename);
    }


    //出证单位导出
    public function czdwExportExcel(
        Request            $request,
        Excel              $excel,
        UnitInfo           $info,
        \app\service\Order $order,
        \app\service\Order $orderSer,
        \app\service\CustomManage $customManage,
        UnitInfo                  $unit,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->get('id');
        $type = $request->get('type') ?: 1;
        $all = $request->get ('all');
        $uid = $request->get('user_login_id');
        $param = $request->get ();

        if (empty($id) || empty($type)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);


        if ($type == 1) {
            $title = '出证单位导出';
            $headerTitle = '主营业务';
        }
        if ($type == 2) {
            $title = '聘用单位导出';
            $headerTitle = '资质类别';
        }
        if ($type == 3) {
            $title = '注册单位导出';
            $headerTitle = '资质类别';
        }
        if ($all){

            $ids = $customManage->spliceWhere($param); //权限

            //拼接查询订单量
            $datas = $orderSer->getCzdwOrderNum($unit->getTypeListModel($type, '', '', $ids),$uid);

            $data = $orderSer->delOrderEmpty($datas);
        }else{
            //出证单位数据
            $data = $info->getTypeDataModel($type, $id);
            $data = $orderSer->getCzdwOrderNum($data, $uid);
        }

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'title', 's_value' => '企业名称', 's_width' => 10],
            ['s_cell' => 'contacts', 's_value' => '联系人', 's_width' => 10],
            ['s_cell' => 'mobile', 's_value' => '联系电话', 's_width' => 10],
            ['s_cell' => 'area', 's_value' => '所属区域', 's_width' => 10],
            ['s_cell' => 'address', 's_value' => '详细地址', 's_width' => 10],
            ['s_cell' => 'establish_date', 's_value' => '成立时间', 's_width' => 10],
            ['s_cell' => 'qualifications_type', 's_value' => $headerTitle, 's_width' => 10],
            ['s_cell' => 'secure_expire_date', 's_value' => '安全到期时间', 's_width' => 10],
            ['s_cell' => 'register_price', 's_value' => '注册资金', 's_width' => 10],
            ['s_cell' => 'order_goods_number', 's_value' => '订单', 's_width' => 10],
//            ['s_cell'=>'create_date','s_value'=>'创建时间','s_width'=>10]
        ];
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$RECYCLE,$title);
        $excel->outExcelStart($data, $header, $title);
    }

    //业务管理
    //业绩总表导出
    public function yjzbExportExcel(
        Request       $request,
        Excel         $excel,
        OrderDeal     $deal,
        FinanceServer $financeServer,
        Power         $power,
        SystemOperateLog $systemOperateLogModel,
        RedisService $redisService,
        UserOrganization $organizationModel,
        System $systemSer
    ){
        $param = json_decode($request->param('arr'), true);

        $where = $request->param ();
        $all = $request->param('all');
        $uid = $request->get ('user_login_id');
        //根据条件查询用户范围
        $userIdData = $power->getUserDataRange($uid);

        if (empty($param)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        //查询所有成交过的订单
//        $dealData = $deal->getOrderList();
        $dataId = $financeServer->getOrderDataIdData ($userIdData);

        $datas = [];
        $data = [];
        $chids = [];
        if (!empty($dataId)){
            //获取各业务缓存
            $datas = $redisService->getPerformanceList ($dataId,$userIdData,$uid);
        }
        //先筛选
        unset($where['id']);
        $where['cw_status'] = $param['status'] ?? '';
        $where['status'] = '';
        $datasd = $financeServer->resultSearchHandle ($where,$datas);

        //选择某些值导出
        if(!$all){
            $idCerArr = array_column ($param,'certificate_code','id');

            foreach ($datasd as $datum) {
                if (isset($datum['childs'])){

                    foreach ($datum['childs'] as $its) {
                        if (in_array ($its['certificate_code'],$idCerArr)){
                            $data[] = $its;
                        }
                    }
                }

                if (!isset($idCerArr[$datum['id']])){
                    continue;
                }
                if ($datum['certificate_code'] == $idCerArr[$datum['id']]){
                    $data[] = $datum;
                }
            }
        }else{
//            echo 1;die;
            foreach ($datasd as $it) {
                if (isset($it['childs'])){
                    foreach ($it['childs'] as $child) {
                        $data[] = $child;
                    }
                }
                $data[] = $it;
            }
        }


 /**
         * 列表上方公司部门 人员筛选 ||条件
         * 搜索设计全局没有 或者 条件
         */
        //  print_r($where);die;
        $orgData = $organizationModel->getStructure();
        if (isset($where['input_org']) && $where['input_org']){  //接收值ID
            unset($item);
            foreach ($data as $ke => $item) {
                if (isset($where['input_uid']) && $where['input_uid']){ //接受值TEXT
                    if (stripos($item['out_uid']['text'],$where['input_uid']) === false && stripos($item['get_uid']['text'],$where['input_uid']) === false){
                        unset($data[$ke]);
                        continue;
                    }
                }
                $orgArr = explode(',', rtrim($systemSer->getOrgIdStr($where['input_org'], $orgData), ','));

                if (!in_array($item['out_org']['id'], $orgArr) && !in_array($item['get_org']['id'] , $orgArr)) {
                    unset($data[$ke]);
                }

            }
        }
        $data = array_values ($data);
        $orderData = my_sort($data,'sale_date',SORT_DESC);

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'certificate_code', 's_value' => '订单编号', 's_width' => 10],
            ['s_cell' => 'sale_date', 's_value' => '销售日期', 's_width' => 10],
            ['s_cell' => 'business_id', 's_value' => '业务类型', 's_width' => 10],
            ['s_cell' => 'order_status', 's_value' => '订单类型', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
            ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
            ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
            ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
            ['s_cell' => 'get_org', 's_value' => '收证部门', 's_width' => 10],
            ['s_cell' => 'get_uid', 's_value' => '收证人员', 's_width' => 10],
            ['s_cell' => 'out_org', 's_value' => '出证部门', 's_width' => 10],
            ['s_cell' => 'out_uid', 's_value' => '出证人员', 's_width' => 10],
            ['s_cell' => 'sale_price', 's_value' => '收证价', 's_width' => 10],
            ['s_cell' => 'contract_price', 's_value' => '出证价', 's_width' => 10],
            ['s_cell' => 'performance', 's_value' => '业绩', 's_width' => 10],
            ['s_cell' => 'get_price_date', 's_value' => '收款时间', 's_width' => 10],
            ['s_cell' => 'get_price_all', 's_value' => '已收款', 's_width' => 10],
            ['s_cell' => 'out_price_date', 's_value' => '付款时间', 's_width' => 10],
            ['s_cell' => 'out_price_all', 's_value' => '已付款', 's_width' => 10],
            ['s_cell' => 'status', 's_value' => '订单状态', 's_width' => 10],
            ['s_cell' => 'td_date', 's_value' => '退单时间', 's_width' => 10],
            ['s_cell' => 'td_performance', 's_value' => '退单业绩', 's_width' => 10],
            ['s_cell' => 'label', 's_value' => '备注', 's_width' => 10],
            ['s_cell' => 'sfk_status', 's_value' => '收/付款状态', 's_width' => 10],
            ['s_cell' => 'sfk_wc_date', 's_value' => '完成时间', 's_width' => 10],
        ];

        /**
         * 计算合计  业绩  收证价 出证价 已付款  已收款 退单业绩
         */
        $sumData = [
            'certificate_code'=>'总计',
            'performance'=>0,//业绩
            'sale_price'=>0,//收证价
            'contract_price'=>0,//出证价
            'out_price_all'=>0,//已付款
            'get_price_all'=>0,//已收款
            'td_performance'=>0 //退单业绩
        ];
        foreach ($data as $value) {
            $sumData['performance'] += (int)$value['performance'];
            $sumData['sale_price'] += (int)$value['sale_price'];
            $sumData['contract_price'] += (int)$value['contract_price'];
            $sumData['out_price_all'] += (int)$value['out_price_all'];
            $sumData['get_price_all'] += (int)$value['get_price_all'];
            $sumData['td_performance'] += (int)($value['td_performance']??0);
        }
        $orderData[] = $sumData;

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$CWGL,'业绩总表导出');

        $excel->outExcelStart($orderData, $header, '业绩总表导出');
    }


    //收款单导出
    public function skdExportExcel(
        Request                $request,
        Excel                  $excel,
        UnitInfo               $info,
        OrderTransactionRecord $transactionRecord,
        FinanceServer          $financeServer,
        \app\service\Order     $order,
        Power                  $power,
        SystemOperateLog       $systemOperateLogModel,
        RedisService $redisService
    )
    {
        $id = $request->param('id');
        $id = explode(',', $id);
        $uid = $request->param ('user_login_id');
        $all = $request->param ('all');
        $param = $request->param ();
        $page = $request->param('page') ?: 1;
        $pageNum = $request->param('pageNum') ?: stateData::$_page;
        $transaction_type = 1;

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if ($all){
            $userData = $power->getUserDataRange($uid);
            $dataId = $transactionRecord->getTransactionListModel($transaction_type,$userData,$uid,$page,$pageNum);
        } else {
            $dataId = $transactionRecord->getTypeDataModel($id, $transaction_type);
        }

        unset($param['id']);
        //搜索结果做搜索处理
        $result = $order->addTransactionField ($redisService->getTransactionReList ($dataId));
        $data = $financeServer->resultSearchHandle($param, $result);
        $data = my_sort($data,'transaction_date',SORT_DESC);

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
//            ['s_cell' => 'transaction_code', 's_value' => '收款单号', 's_width' => 10],
//            ['s_cell' => 'certificate_code', 's_value' => '关联订单号', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'receivable', 's_value' => '应收金额', 's_width' => 10],
            ['s_cell' => 'yishou', 's_value' => '之前收款', 's_width' => 10],
            ['s_cell' => 'price', 's_value' => '本次收款金额', 's_width' => 10, 'text' => 'int'],
            ['s_cell' => 'type', 's_value' => '收款类型', 's_width' => 10],
            ['s_cell' => 'transaction_uid', 's_value' => '提交人', 's_width' => 10],
            ['s_cell' => 'transaction_date', 's_value' => '到账时间', 's_width' => 10],
            ['s_cell' => 'notes', 's_value' => '收款事由', 's_width' => 10],
            ['s_cell' => 'transaction_date', 's_value' => '提交时间', 's_width' => 10],
            ['s_cell' => 'refuse_text', 's_value' => '审批意见', 's_width' => 10],
            ['s_cell' => 'certificate_code', 's_value' => '关联订单号', 's_width' => 10],
            ['s_cell' => 'status', 's_value' => '状态', 's_width' => 10],
            ['s_cell' => 'annex', 's_value' => '收款凭证', 's_width' => 10],

        ];
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$CWGL,message::$EXPORT);
        $excel->outExcelStart($data, $header, '收款单导出');
    }

    //付款单导出
    public function fkdExportExcel(
        Request                $request,
        Excel                  $excel,
        UnitInfo               $info,
        OrderTransactionRecord $transactionRecord,
        FinanceServer          $financeServer,
        \app\service\Order     $order,
        Power                  $power,
        SystemOperateLog       $systemOperateLogModel,
        RedisService $redisService
    ){
        $id = $request->param('id');
        $id = explode(',', $id);
        $uid = $request->param('user_login_id');
        $all = $request->param('all');
        $param = $request->param();
        $page = $request->param ('page')?:1;
        $pageNum = $request->param ('pageNum')?:stateData::$_page;

        $transaction_type = 2;
        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if ($all){
            $userData = $power->getUserDataRange($uid);
            $dataId = $transactionRecord->getTransactionListModel($transaction_type,$userData,$uid,$page,$pageNum);

        }else{
            $dataId = $transactionRecord->getTypeDataModel($id, $transaction_type);
        }
        unset($param['id']);

        $result = $order->addTransactionField ($redisService->getTransactionReList ($dataId));
        //搜索结果做搜索处理
        $data = $financeServer->resultSearchHandle($param, $result);
        $data = my_sort($data,'transaction_date',SORT_DESC);
        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'yingfu', 's_value' => '应付金额', 's_width' => 10],
            ['s_cell' => 'yifu', 's_value' => '之前付款', 's_width' => 10],
            ['s_cell' => 'price', 's_value' => '本次付款金额', 's_width' => 10],
            ['s_cell' => 'type', 's_value' => '付款类型', 's_width' => 10],
            ['s_cell' => 'settlement_method', 's_value' => '结算方式', 's_width' => 10],
            ['s_cell' => 'transaction_uid', 's_value' => '提交人', 's_width' => 10],
            ['s_cell' => 'transaction_date', 's_value' => '付款时间', 's_width' => 10],
            ['s_cell' => 'notes', 's_value' => '付款事由', 's_width' => 10],
            ['s_cell' => 'refuse_text', 's_value' => '审批意见', 's_width' => 10],
//            ['s_cell' => 'transaction_code', 's_value' => '付款单号', 's_width' => 10],
            ['s_cell' => 'certificate_code', 's_value' => '关联订单号', 's_width' => 10],
            ['s_cell' => 'status', 's_value' => '状态', 's_width' => 10],
            ['s_cell' => 'annex', 's_value' => '付款凭证', 's_width' => 10],
        ];


        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$CWGL,message::$EXPORT);
        $excel->outExcelStart($data, $header, '付款单导出');
    }


    //证书审核导出
    public function zsshExportExcel(
        Request                        $request,
        Excel                          $excel,
        Clue                           $clue,
        OrderPersonCertificateRegister $certificateRegister,
        Power                          $power,
        \app\service\OrderCertExamine  $orderCertExamine,
        \app\service\Order $orderSer,
        Image $image,
        SystemOperateLog $systemOperateLogModel,
        RedisService $redisService
    ){
        $id = $request->param('id');
        $uid = $request->param('user_login_id');
        $all = $request->param ('all');
        $manage = $request->param ('manage'); // 1个人 2管理
        //根据条件查询用户范围
        $userData = $power->getUserDataRange($request->param('user_login_id'));

        $param = $request->param ();

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if ($all){

            $flag = flagStatus($param);
            $ids = $orderCertExamine->spliceWhere($param);
            $ids = !$ids ? [0] : $ids;

            if($manage == 1){
                $all_ids = $certificateRegister->getWhereThatPersonInStatusIds('-1,0,1,2,3,4,5', $uid);
                $ids = handlePersonIds($all_ids, $ids, $flag);

                $dataId = $certificateRegister->getWhereThatPersonInStatusAllList('-1,0,1,2,3,4,5', $uid, $ids,'');
            }else{
                $all_ids = $certificateRegister->getWhereInStatusIds('-1,0,1,2,3,4,5',$userData);
                $ids = handlePersonIds($all_ids, $ids, $flag);
                $dataId = $certificateRegister->getWhereInStatusAllList('-1,0,1,2,3,4,5', $ids,'');
            }

        }else{
            $dataId = $certificateRegister->getExcelList('0,1,2', $id);
        }
        $data = $redisService->getOrderZsshData ($dataId,$uid);

        $data = $image->handleList($data,['contract_file','information_file'],true);

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'certificate_characteristic', 's_value' => '证书特性', 's_width' => 10],
            ['s_cell' => 'acquisition_date', 's_value' => '收证时间', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
            ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
            ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
            ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
            ['s_cell' => 'certificate_b', 's_value' => 'B证', 's_width' => 10],
            ['s_cell' => 'social_security', 's_value' => '社保', 's_width' => 10],
            ['s_cell' => 'project', 's_value' => '项目', 's_width' => 10],
            ['s_cell' => 'cycle', 's_value' => '周期', 's_width' => 10],
            ['s_cell' => 'catual_price', 's_value' => '实际收证价', 's_width' => 10],
            ['s_cell' => 'person_account', 's_value' => '人才账号', 's_width' => 10],
            ['s_cell' => 'person_password', 's_value' => '密码', 's_width' => 10],
            ['s_cell' => 'notes', 's_value' => '备注信息', 's_width' => 10],
            ['s_cell' => 'zj_account', 's_value' => '住建账号', 's_width' => 10],
            ['s_cell' => 'zj_password', 's_value' => '住建密码', 's_width' => 10],
            ['s_cell' => 'reject_text', 's_value' => '驳回原因', 's_width' => 10],
            ['s_cell' => 'get_org', 's_value' => '收证部门', 's_width' => 10],
            ['s_cell' => 'get_uid', 's_value' => '收证人员', 's_width' => 10],
            ['s_cell' => 'status', 's_value' => '状态说明', 's_width' => 10],
            ['s_cell' => 'certificate_characteristic_status', 's_value' => '特价状态', 's_width' => 10],


//            ['s_cell' => 'certificate_code', 's_value' => '证书编号', 's_width' => 10],
//            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
//            ['s_cell' => 'social_security_acc_status', 's_value' => '社保账户', 's_width' => 10],
//            ['s_cell' => 'b_doc_status', 's_value' => 'B证是否调入', 's_width' => 10],
//            ['s_cell' => 'transfer', 's_value' => '是否中转', 's_width' => 10],
//            ['s_cell' => 'contract_price', 's_value' => '合同价', 's_width' => 10],
//            ['s_cell' => 'person_price','s_value'=>'人才应付价','s_width'=>10],
//            ['s_cell' => 'mobile', 's_value' => '手机号', 's_width' => 10],
//            ['s_cell' => 'information_file', 's_value' => '资料文件', 's_width' => 10],
//            ['s_cell' => 'contract_file', 's_value' => '合同附件', 's_width' => 10],

        ];
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$ORDER,'证书审核导出');
        $excel->outExcelStart($data, $header, '证书审核导出');
    }

    //证书办理导出
    public function zsblExportExcel(
        Request                       $request,
        Excel                         $excel,
        OrderOtherCertificateBusiness $otherBusiness,
        Clue                          $clue,
        OrderDealChargeback $chargebackModel,
        Power                         $power,
        OrderOtherCertificateBusiness $handle,
        \app\service\Order            $orderSer,
        OrderCertTransact             $orderCertTransact,
        FinanceServer $financeServer,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->param('id');
        $uid = $request->param('user_login_id');
        $all = $request->param ('all');
        $manage = $request->param ('manage');// 1个人 2管理
        $param = $request->param ();
        //根据条件查询用户范围
        $userData = $power->getUserDataRange($request->param('user_login_id'));
        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if ($all){
            if($manage == 1){
                $flag = flagStatus($param);

                $ids = $orderCertTransact->spliceWhere($param);

                $ids = !$ids ? [0] : $ids;
                $all_ids = $handle->getThatPersonDataIds($request->param('user_login_id'));
                $ids = handlePersonIds($all_ids, $ids, $flag);
                //getOrderIsOp 查询是否有退单或者注销操作
                $datas = $handle->getThatPersonDataModel($uid, $ids);

                $result = $orderSer->getMianOrderInfo ($orderSer->getOrderIsOp($datas));

            }else{
                $flag = flagStatus($param);
                $ids = $orderCertTransact->spliceWhere($param);
                $ids = !$ids ? [0] : $ids;

                $all_ids = $handle->getDataIds($userData);
                $ids = handlePersonIds($all_ids, $ids, $flag);
                $datas = $handle->getDataModel('', '', $ids);
                $result = $orderSer->getMianOrderInfo ($orderSer->getOrderIsOp($clue->personData($datas,$uid)));
            }
        }else{
            $result = $otherBusiness->getExcelModel($id);
        }

        //查询退单
        $chargebackData = $chargebackModel->getCharDataModel();
        if (!empty($chargebackData)){
            foreach ($chargebackData as $chargebackDatum) {
                $tData = $otherBusiness->getCerDataModel($chargebackDatum['certificate_code']);

                if ($tData){
                    //判断个人还是管理 增加响应退单内容
                    $idArr = array_column ($result,'id');

                    if(in_array ($tData['id'],$idArr)){

                        $tData['performance'] = $chargebackDatum['performance'];

                        $tData['create_date'] = $chargebackDatum['create_date'];
                        $tData['sale_date'] = $chargebackDatum['create_date'];
                        $tData['tuidan'] = true;
                        $tData['reason'] = $chargebackDatum['reason'];
                        $tData['status'] = [
                            'id'=>999,
                            'text'=>'退单完成'
                        ];
                        $result[] = $tData;
                    }
                }
            }
        }
        $where['start_performance'] = $param['start_performance'] ?? '';
        $where['end_performance'] = $param['end_performance'] ?? '';
        $where['c_status'] = $param['status'];
        $where['start_sale_date'] = $param['sale_start_date'];
        $where['end_sale_date'] = $param['sale_end_date'];

        //条件筛选
        $ds = $financeServer->resultSearchHandle ($where,$result);

        $data = my_sort($clue->personData($ds, $uid),'sale_date',SORT_DESC);
        /**
         * 保证导出数据与选择数据一致
         */
       if (!$all){
           $jid = explode (',',$param['id']);
           $jstatus = explode (',',$param['statuss']);
           $reData = [];
           foreach ($data as $item) {
               if (in_array ($item['id'],$jid)){
                   if ($jstatus[array_search($item['id'],$jid)] == $item['status']['id']){
                       $reData[] = $item;
                       if (isset($jid[array_search($item['id'],$jid)])){
                           unset($jid[array_search($item['id'],$jid)]);
                       }
                   }
               }
           }
       }else{
           $reData = $data;
       }

        //附属单处理
        foreach ($reData as &$reDatum) {
            if($reDatum['type'] == 1){
                $reDatum['type'] = '是';
            }else{
                $reDatum['type'] = '否';
            }
        }
        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'type', 's_value' => '是否附属单', 's_width' => 10],
            ['s_cell' => 'sale_date', 's_value' => '销售日期', 's_width' => 10],
            ['s_cell' => 'business_id', 's_value' => '业务类型', 's_width' => 10],
            ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'get_org', 's_value' => '销售部门', 's_width' => 10],
            ['s_cell' => 'get_uid', 's_value' => '销售人员', 's_width' => 10],
            ['s_cell' => 'cost_price', 's_value' => '成本价格', 's_width' => 10],
            ['s_cell' => 'sale_price', 's_value' => '销售价格', 's_width' => 10],
            ['s_cell' => 'performance', 's_value' => '业绩', 's_width' => 10],
            ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
            ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
            ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
            ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
            ['s_cell' => 'status', 's_value' => '状态说明', 's_width' => 10],

//            ['s_cell' => 'certificate_code', 's_value' => '证书编号', 's_width' => 10],
//            ['s_cell' => 'person_id_card', 's_value' => '身份证号', 's_width' => 10],
//            ['s_cell' => 'information_file', 's_value' => '资料信息', 's_width' => 10],
//            ['s_cell' => 'contract_file', 's_value' => '合同附件', 's_width' => 10],
//            ['s_cell' => 'reason', 's_value' => '退单原因', 's_width' => 10],

        ];

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$ORDER,'证书办理导出');
        $excel->outExcelStart($reData, $header, '证书办理导出');
    }

    //企业证书导出
    public function qyzsExportExcel(
        Request                            $request,
        Excel                              $excel,
        OrderEnterpriseCertificateBusiness $business,
        OrderDealChargeback $chargebackModel,
        Power                              $power,
        OrderEnterpriseCertificateBusiness $enCre,
        \app\service\Order                 $orderSer,
        OrderEnterCert                     $orderEnterCert,
        Image $image,
        FinanceServer $financeServer,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->param('id');
        $all = $request->param ('all');
        $manage = $request->param ('manage');
        $param = $request->get();
        $uid = $request->get ('user_login_id');
        //根据条件查询用户范围
        $userData = $power->getUserDataRange($uid);
        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if($all){

            if ($manage == 1){
                $flag = flagStatus($param);
                $ids = $orderEnterCert->spliceWhere($param);
                $ids = !$ids ? [0] : $ids;
                $all_ids = $enCre->getThatPersonDataIds($uid);
                $ids = handlePersonIds($all_ids, $ids, $flag);

                $ids[] = $request->get ('user_login_id'); //添加当前登陆人

                $data = $enCre->getThatPersonDataModel($uid, $ids);
            }else{
                $flag = flagStatus($param);
                $ids = $orderEnterCert->spliceWhere($param);

                $ids = !$ids ? [0] : $ids;
                $all_ids = $enCre->getDataIds($userData);

                $ids = handlePersonIds($all_ids, $ids, $flag);

                //getOrderIsOp 判断是否有退单或者注销状态
                $data = $enCre->getDataModel('', '', $ids);
            }

        }else{
            $data = $business->getExcelModel($id);
        }


        //查询退单
        $chargebackData = $chargebackModel->getCharDataModel();
        if (!empty($chargebackData)){
            foreach ($chargebackData as $chargebackDatum) {
                $tData = $business->getCerDataModel($chargebackDatum['certificate_code']);

                //判断个人还是管理 增加响应退单内容
                $idArr = array_column ($data,'id');
                if(in_array ($tData['id'],$idArr)){
                    if ($tData){
                        $tData['performance'] = $chargebackDatum['performance'];

                        $tData['create_date'] = $chargebackDatum['create_date'];
                        $tData['sale_date'] = $chargebackDatum['create_date'];
                        $tData['tuidan'] = true;
                        $tData['reason'] = $chargebackDatum['reason'];
                        $tData['status'] = [
                            'id'=>999,
                            'text'=>'退单完成'
                        ];
                        $data[] = $tData;
                    }
                }

            }
        }

        $where['start_performance'] = $param['start_performance'] ?? '';
        $where['end_performance'] = $param['end_performance'] ?? '';
        $where['c_status'] = $param['status'];
        $where['start_sale_date'] = $param['sale_start_date'];
        $where['end_sale_date'] = $param['sale_end_date'];

        //条件筛选
        $ds = $financeServer->resultSearchHandle ($where,$data);

        $data = my_sort($ds,'sale_date',SORT_DESC);
        /**
         * 保证导出数据与选择数据一致
         */
        if (!$all){
            $jid = explode (',',$param['id']);
            $jstatus = explode (',',$param['statuss']);

            $reData = [];
            foreach ($data as $item) {
                if (in_array ($item['id'],$jid)){
                    if ($jstatus[array_search($item['id'],$jid)] == $item['status']['id']){
                        $reData[] = $item;
                        if (isset($jid[array_search($item['id'],$jid)])){
                            unset($jid[array_search($item['id'],$jid)]);
                        }
                    }
                }
            }
        }else{
            $reData = $data;
        }



        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'sale_date', 's_value' => '销售日期', 's_width' => 10],
            ['s_cell' => 'business_id', 's_value' => '业务类型', 's_width' => 10],
            ['s_cell' => 'business_category', 's_value' => '业务类别', 's_width' => 10],
            ['s_cell' => 'business_text', 's_value' => '业务内容', 's_width' => 10],
            ['s_cell' => 'get_org', 's_value' => '收证部门', 's_width' => 10],
            ['s_cell' => 'get_uid', 's_value' => '收证人员', 's_width' => 10],
            ['s_cell' => 'out_org', 's_value' => '出证部门', 's_width' => 10],
            ['s_cell' => 'out_uid', 's_value' => '出证人员', 's_width' => 10],
            ['s_cell' => 'cost_price', 's_value' => '成本价格', 's_width' => 10],
            ['s_cell' => 'sale_price', 's_value' => '销售价格', 's_width' => 10],
            ['s_cell' => 'performance', 's_value' => '业绩', 's_width' => 10],
            ['s_cell' => 'enterprise_name', 's_value' => '企业名称', 's_width' => 10],
            ['s_cell' => 'contacts', 's_value' => '联系人', 's_width' => 10],
            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
            ['s_cell' => 'notes', 's_value' => '备注', 's_width' => 10],
            ['s_cell' => 'status', 's_value' => '状态说明', 's_width' => 10],

        ];

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$ORDER,'企业证书导出');
        $excel->outExcelStart($reData, $header, '企业证书导出');
    }

    //证书注册-倒证导出
    public function zszcDzExportExcel(
        Request                 $request,
        Excel                   $excel,
        OrderEnterpriseExchange $exchange,
        \app\service\Publicity  $publicity,
        OrderDealChargeback $chargebackModel,
        OrderCertReverseCase               $orderCertReverseCase,
        FinanceServer $financeServer,
        Power $power,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->param('id');
        $all = $request->param('all');
        $manage = $request->param('manage');
        $param = $request->param();
        $uid = $request->param('user_login_id');
        $info_generate_exist = $request->param('info_generate_exist'); //0-不存在 1-存在
        //根据条件查询用户范围
        $userData = $power->getUserDataRange($request->param('user_login_id'));
        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if ($all) {
            if ($manage == 1) {
                $flag = flagStatus($param);
                $ids = $orderCertReverseCase->spliceWhere($param);
                $ids = !$ids ? [0] : $ids;
                $all_ids = $exchange->getOtherExchangeListIds($uid);
                $ids = handlePersonIds($all_ids, $ids, $flag);

                //获取个人提交倒证 getOrderIsOp 判断是否有退单|注销
                $datas = $exchange->getOtherExchangeListModel($uid, '', '', $ids);

            } else {
                $flag = flagStatus($param);
                $ids = $orderCertReverseCase->spliceWhere($param);
                $ids = !$ids ? [0] : $ids;
                $all_ids = $exchange->getExchangeListIds($userData);
                $ids = handlePersonIds($all_ids, $ids, $flag);

                $datas = $exchange->getExchangeAllListModel('', '', $ids);
            }

        } else {
            $datas = $exchange->getExcelModel($id);
        }


        //查询退单
        $chargebackData = $chargebackModel->getCharDataModel();
        if (!empty($chargebackData)) {
            foreach ($chargebackData as $chargebackDatum) {
                $tData = $exchange->getFinanceFieldFindModel($chargebackDatum['certificate_code']);

                if ($tData) {
                    //判断个人还是管理 增加响应退单内容
                    $idArr = array_column($datas, 'id');
                    if (in_array($tData['id'], $idArr)) {
                        $tData['performance'] = $chargebackDatum['performance'];

                        $tData['create_date'] = $chargebackDatum['create_date'];
                        $tData['sale_date'] = $chargebackDatum['create_date'];
                        $tData['tuidan'] = true;
                        $tData['reason'] = $chargebackDatum['reason'];
                        $tData['status'] = [
                            'id' => 999,
                            'text' => '退单完成'
                        ];
                        $datas[] = $tData;
                    }
                }
            }
        }
        $result = $publicity->getPublicyInfo($datas, $uid);

        $jid = $param['id'];
        $jstatus = explode(',', $param['statuss']);
        unset($param['id']);

        //数组搜索
        $result = $financeServer->resultSearchHandle($param, $result);

        $results = my_sort($result, 'sale_date', SORT_DESC);

        /**
         * 保证导出数据与选择数据一致
         */
        if (!$all) {
            $jid = explode(',', $jid);
            $reData = [];
            foreach ($results as $item) {
                if (in_array($item['id'], $jid)) {
                    if ($jstatus[array_search($item['id'], $jid)] == $item['status']['id']) {
                        $reData[] = $item;
                        if (isset($jid[array_search($item['id'], $jid)])) {
                            unset($jid[array_search($item['id'], $jid)]);
//                           unset($jstatus[array_search($item['id'],$jid)]);
                        }
                    }
                }
            }
        } else {
            $reData = $results;
        }

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'sale_date', 's_value' => '销售日期', 's_width' => 10],
            ['s_cell' => 'business_id', 's_value' => '业务类型', 's_width' => 10],
            ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'order_status', 's_value' => '订单类型', 's_width' => 10],
            ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
            ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
            ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
            ['s_cell' => 'certificate_b', 's_value' => 'B证', 's_width' => 10],
            ['s_cell' => 'get_org', 's_value' => '收证部门', 's_width' => 10],
            ['s_cell' => 'get_uid', 's_value' => '收证人员', 's_width' => 10],
            ['s_cell' => 'out_org', 's_value' => '出证部门', 's_width' => 10],
            ['s_cell' => 'out_uid', 's_value' => '出证人员', 's_width' => 10],
            ['s_cell' => 'get_price', 's_value' => '收证价', 's_width' => 10],
            ['s_cell' => 'out_price', 's_value' => '出证价', 's_width' => 10],
            ['s_cell' => 'performance', 's_value' => '业绩', 's_width' => 10],
            ['s_cell' => 'b_reg_electronic_certificate_date', 's_value' => '注册注销时间', 's_width' => 10],
            ['s_cell' => 'cycle', 's_value' => '周期', 's_width' => 10],
            ['s_cell' => 'social_security', 's_value' => '社保', 's_width' => 10],
            ['s_cell' => 'project', 's_value' => '项目', 's_width' => 10],
            ['s_cell' => 'transfer', 's_value' => '是否中转', 's_width' => 10],
            ['s_cell' => 'unit_reg_title', 's_value' => '注册单位', 's_width' => 10],
            ['s_cell' => 'employ_unit_title', 's_value' => '聘用单位', 's_width' => 10],
            ['s_cell' => 'out_unit', 's_value' => '供证单位', 's_width' => 10],

//            ['s_cell' => 'certificate_code', 's_value' => '订单编号', 's_width' => 10],
//            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
//            ['s_cell' => 'employ_unit_name', 's_value' => '聘用单位联系人', 's_width' => 10],
//            ['s_cell' => 'employ_unit_mobile', 's_value' => '聘用单位联系方式', 's_width' => 10],
            ['s_cell' => 'electronic_certificate_date', 's_value' => '证书到期时间', 's_width' => 10],
            ['s_cell' => 'b_electronic_certificate_date', 's_value' => 'B证到期时间', 's_width' => 10],

//            ['s_cell' => 'out_name', 's_value' => '出证单位联系人', 's_width' => 10],
//            ['s_cell' => 'out_mobile', 's_value' => '出证单位联系方式', 's_width' => 10],
//            ['s_cell' => 'id_card', 's_value' => '身份证号', 's_width' => 10],
//            ['s_cell' => 'reg_file', 's_value' => '上传注册表', 's_width' => 10],
//            ['s_cell' => 'info_file', 's_value' => '上传注册信息', 's_width' => 10],
//            ['s_cell' => 'reason', 's_value' => '退单原因', 's_width' => 10],
//            ['s_cell' => 'electronic_certificate_file', 's_value' => '电子证书', 's_width' => 10],
//            ['s_cell' => 'b_electronic_certificate_file', 's_value' => 'B证电子证书', 's_width' => 10],


        ];
        if($info_generate_exist){
            $header[] = ['s_cell' => 'info_generate_status', 's_value' => '信息生成', 's_width' => 10];
        }
        $header[] = ['s_cell' => 'status', 's_value' => '状态说明', 's_width' => 10];

        //添加日志
        $systemOperateLogModel->addOperate($uid, message::$ORDER, '企业证书注册-倒证导出');
        $excel->outExcelStart($reData, $header, '企业证书注册-倒证导出');
    }

    //证书注册-公司证书导出
    public function zszcGszsExportExcel(
        Request                $request,
        Excel                  $excel,
        OrderEnterpriseCompany $OrderEnterpriseCompany,
        OrderEnterpriseCertificateRegister $certificateRegister,
        OrderDeal              $orderDeal,
        Certificate            $certificate,
        OrderDealChargeback $chargebackModel,
        FinanceServer $financeServer,
        Power $power,
        SystemOperateLog $systemOperateLogModel,
        RedisService $redisService
    ){
        $id = $request->param('id');
        $all = $request->param ('all');
        $manage = $request->param('manage');
        $param = $request->param ();
        $uid = $request->param ('user_login_id');

        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        //根据条件查询用户范围
        $userData = $power->getUserDataRange($request->param('user_login_id'));

        if ($all){
            if($manage == 1){
                $dataId = $OrderEnterpriseCompany->getCompanyListUidModel('', '', $uid);
            }else{
                $dataId = $OrderEnterpriseCompany->getCompanyListModel($userData,'', '');
            }

        }else{
            $dataId = $OrderEnterpriseCompany->getIdDataModel ($id);
        }

        //查询退单
        $chargebackData = $chargebackModel->getCharDataModel();
        if (!empty($chargebackData)){
            foreach ($chargebackData as $chargebackDatum) {
                $tData = $OrderEnterpriseCompany->getIdCertificateCodeFindModel($chargebackDatum['order_company_id'],$chargebackDatum['certificate_code']);

                if ($tData) {
                    //判断个人还是管理 增加响应退单内容
                    $idArr = array_column ($dataId, 'id');
                    if (in_array ($tData['id'], $idArr)) {
//                        $tData['performance'] = $chargebackDatum['performance'];
//
//                        $tData['create_date'] = $chargebackDatum['create_date'];
                        $tData['sale_date'] = $chargebackDatum['create_date'];
//                        $tData['tuidan'] = true;
//                        $tData['reason'] = $chargebackDatum['reason'];
//                        $tData['status'] = [
//                            'id' => 999,
//                            'text' => '退单完成'
//                        ];
                        $dataId[] = $tData;
                    }
                }
            }
        }

        $result = $redisService->getOrderReKeyDataList ($dataId,$uid,'order_gszs');
        $excelId = '';
        //使用模型转换器转换
        foreach ($result as &$value) {
            $excelId .= $value['id'].',';
        }

        $jid = $param['id'];
        unset($param['id']);
        $jstatus = explode (',',$param['statuss']);

        //处理搜索条件
        $result = $financeServer->resultSearchHandle ($param,$result);

        /**
         * 保证导出数据与选择数据一致
         */
        $reData = [];
        if (!$all){
            $jid = explode (',',$jid);

            foreach ($result as $item) {
                if (in_array ($item['id'],$jid)){
                    if ($jstatus[array_search($item['id'],$jid)] == $item['status']['id']){
                        $reData[] = $item;
                        if (isset($jid[array_search($item['id'],$jid)])){
                            unset($jid[array_search($item['id'],$jid)]);
                        }
                    }
                }
            }
        }else{
            $reData = $result;
        }


        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'sale_date', 's_value' => '销售日期', 's_width' => 10],
            ['s_cell' => 'business_id', 's_value' => '业务类型', 's_width' => 10],
            ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
            ['s_cell' => 'person_name', 's_value' => '人才姓名', 's_width' => 10],
            ['s_cell' => 'order_status', 's_value' => '订单类型', 's_width' => 10],
            ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
            ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
            ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
            ['s_cell' => 'certificate_b', 's_value' => 'B证', 's_width' => 10],
            ['s_cell' => 'get_org', 's_value' => '收证部门', 's_width' => 10],
            ['s_cell' => 'get_uid', 's_value' => '收证人员', 's_width' => 10],
            ['s_cell' => 'sale_org', 's_value' => '销售部门', 's_width' => 10],
            ['s_cell' => 'sale_uid', 's_value' => '销售人员', 's_width' => 10],
            ['s_cell' => 'contract_price', 's_value' => '收证价', 's_width' => 10],
            ['s_cell' => 'price_unit', 's_value' => '出证价', 's_width' => 10],
            ['s_cell' => 'performance', 's_value' => '业绩', 's_width' => 10],
            ['s_cell' => 'b_reg_electronic_certificate_date', 's_value' => '证书注销时间', 's_width' => 10],
            ['s_cell' => 'cycle', 's_value' => '周期', 's_width' => 10],
            ['s_cell' => 'social_security', 's_value' => '社保', 's_width' => 10],
            ['s_cell' => 'project', 's_value' => '项目', 's_width' => 10],
            ['s_cell' => 'reg_unit', 's_value' => '注册单位', 's_width' => 10],
            ['s_cell' => 'employ_unit_title', 's_value' => '聘用单位', 's_width' => 10],
            ['s_cell' => 'electronic_certificate_date', 's_value' => '证书到期时间', 's_width' => 10],
            ['s_cell' => 'b_electronic_certificate_date', 's_value' => 'B证到期时间', 's_width' => 10],
            ['s_cell' => 'status', 's_value' => '状态说明', 's_width' => 10],

//            ['s_cell' => 'certificate_code', 's_value' => '订单编号', 's_width' => 10],
//            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
//            ['s_cell' => 'people_num', 's_value' => '人数', 's_width' => 10],
//
//            ['s_cell' => 'person_id_card', 's_value' => '身份证号', 's_width' => 10],
//            ['s_cell' => 'reg_file_name', 's_value' => '上传注册表', 's_width' => 10],
//            ['s_cell' => 'employ_unit_name', 's_value' => '聘用单位联系人', 's_width' => 10],
//            ['s_cell' => 'employ_unit_mobile', 's_value' => '聘用单位联系方式', 's_width' => 10],
//            ['s_cell' => 'reason', 's_value' => '退单原因', 's_width' => 10],
//            ['s_cell' => 'electronic_certificate_file_illustrate_name', 's_value' => '电子证书', 's_width' => 10],
//            ['s_cell' => 'b_electronic_certificate_file_name', 's_value' => 'B证电子证书', 's_width' => 10],

        ];
        $data = my_sort($reData,'sale_date',SORT_DESC);
        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$ORDER,'公司证书导出ID：'.$excelId);
        $excel->outExcelStart($data, $header, '公司证书导出');
    }

    //证书注册-公司需求导出
    public function zszcGsxqExportExcel(
        Request                            $request,
        Excel                              $excel,
        OrderEnterpriseCertificateRegister $OrderEnterpriseCertificateRegister,
        FinanceServer $financeServer,
        SystemOperateLog $systemOperateLogModel
    ){
        $id = $request->param('id');
        $all = $request->param ('all');
        $manage = $request->param('manage');
        $param = $request->param ();
        $uid = $request->param ('user_login_id');
        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        if($all){
            if ($manage == 1){
                $result = $OrderEnterpriseCertificateRegister->getThatPersonRegCerTypeListModel('1,3', $uid,'');
            }else{
                $result = $OrderEnterpriseCertificateRegister->getRegCerTypeListModel('1,3', '','');

            }
        }else{
            $result = $OrderEnterpriseCertificateRegister->whereIdData($id);
        }
        unset($param['id']);
        //条件筛选
        $data = $financeServer->resultSearchHandle ($param,$result);

        $results = my_sort($data, 'create_date', SORT_ASC);

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'create_date', 's_value' => '创建时间', 's_width' => 10],
            ['s_cell' => 'certificate_leixing', 's_value' => '证书类型', 's_width' => 10],
            ['s_cell' => 'certificate_leibie', 's_value' => '证书类别', 's_width' => 10],
            ['s_cell' => 'certificate_dengji', 's_value' => '等级', 's_width' => 10],
            ['s_cell' => 'certificate_zhuanye', 's_value' => '证书专业', 's_width' => 10],
            ['s_cell' => 'certificate_b', 's_value' => 'B证', 's_width' => 10],
            ['s_cell' => 'social_security', 's_value' => '社保', 's_width' => 10],
            ['s_cell' => 'project', 's_value' => '项目', 's_width' => 10],
            ['s_cell' => 'cycle', 's_value' => '周期', 's_width' => 10],
            ['s_cell' => 'reg_unit', 's_value' => '注册单位', 's_width' => 10],
            ['s_cell' => 'price_unit', 's_value' => '出证价', 's_width' => 10],
            ['s_cell' => 'people_num', 's_value' => '人数', 's_width' => 10],
            ['s_cell' => 'sale_org', 's_value' => '销售部门', 's_width' => 10],
            ['s_cell' => 'sale_uid', 's_value' => '销售人员', 's_width' => 10],
            ['s_cell' => 'gz_status', 's_value' => '状态', 's_width' => 10],
            ['s_cell' => 'order_label', 's_value' => '备注信息', 's_width' => 10],

//            ['s_cell' => 'certificate_code', 's_value' => '订单编号', 's_width' => 10],
//            ['s_cell' => 'business_id', 's_value' => '业务类型', 's_width' => 10],
        ];

        //添加日志
        $systemOperateLogModel->addOperate ($uid,message::$ORDER,'公司需求导出');
        $excel->outExcelStart($results, $header, '公司需求导出');
    }

    //业绩总表-报表中心导出
    public function bbzxExportExcel(Request $request, Excel $excel, OrderEnterpriseCertificateRegister $OrderEnterpriseCertificateRegister)
    {
        $id = $request->param('id');
        if (empty($id)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        $data = $OrderEnterpriseCertificateRegister->whereIdData($id);

        $header = [
            ['s_cell' => 'id', 's_value' => '序号', 's_width' => 10],
            ['s_cell' => 'department_id', 's_value' => '公司部门', 's_width' => 10],
            ['s_cell' => 'nickname', 's_value' => '人员姓名', 's_width' => 10],
            ['s_cell' => 'yjzj', 's_value' => '业绩总数', 's_width' => 10],
            ['s_cell' => 'ylyjzj', 's_value' => '一类业绩总计', 's_width' => 10],
            ['s_cell' => 'elyjzj', 's_value' => '二类业绩总计', 's_width' => 10],
            ['s_cell' => 'zszc_gszs', 's_value' => '公司证书', 's_width' => 10],
            ['s_cell' => 'zszc_dz', 's_value' => '外部证书', 's_width' => 10],
            ['s_cell' => 'zszctj', 's_value' => '总计', 's_width' => 10],
            ['s_cell' => 'zsbltj', 's_value' => '证书办理', 's_width' => 10],
            ['s_cell' => 'qyzstj', 's_value' => '企业证书', 's_width' => 10],
            ['s_cell' => 'yzmb', 's_value' => '月总目标', 's_width' => 10],
            ['s_cell' => 'sjdc', 's_value' => '实际达成', 's_width' => 10],
            ['s_cell' => 'sjjd', 's_value' => '月时间进度', 's_width' => 10],
            ['s_cell' => 'dcjd', 's_value' => '达成进度', 's_width' => 10],

        ];
        $excel->outExcelStart($data, $header, '报表中心导出');
    }

    /********************************************************************************
     * 导入
     * @param \app\Request $request
     * @param \app\service\Excel $excel
     * @param \app\model\WorkPlan $plan
     * @param \app\model\UserMessage $message
     * @return false|string
     */
    //跟进计划导入
    public function planImportExcel(Request $request, Excel $excel, WorkPlan $plan, \app\model\UserMessage $message)
    {
//        Log::error ('导入开始');
        $file = $request->file('file');
//        Log::error ($file.'23');
        Db::startTrans();
        try {
            $data = $excel->PutExcelStart($file, $request->param('user_login_id'));
            $Model = $plan->addDataAll($data);
            //批量成功以后添加消息提醒
            foreach ($Model as $datum) {
                //添加消息列表
                $message->addPlanModel($datum['custom_name'], $request->param('user_login_id'),$request->param('user_login_id'), $datum['id'], $datum['plan_date']);
            }
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
//            return ReJson (message::$ERROR_CODE,message::$UPDATE_FILE_FIELD_ERR);
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }


        return ReJson(message::$SUCC_CODE, message::$SUCC_ALL_INPORT_EXCEL);
    }

    //任务提醒导入
    public function tasksImportExcel(Request $request, Excel $excel, WorkPlan $plan, \app\model\UserMessage $message)
    {
        $file = $request->file('file');

        $data = $excel->PutExcelStart($file, $request->param('user_login_id'));

        Db::startTrans();

        try {
            $Model = $plan->addDataAll($data);
            //批量成功以后添加消息提醒
            foreach ($Model as $datum) {
                //添加消息列表
                $message->addInformationModel($datum['plan_content'], $request->param('user_login_id'),$request->param('user_login_id'), $datum['plan_date']);
            }
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_ALL_INPORT_EXCEL);
    }

    //人才导入
    public function personImportExcel(Request $request, Excel $excel, CluePerson $person, ClueMobile $mobileModel, CluePersonAllocationRecord $allRecord)
    {
        ini_set('memory_limit', '512M');
        $file = $request->file('file');
        Db::startTrans();
        $arr = [
            'import_total' => 0,
            'success_nums' => 0,
            'error_nums' => 0,
            'file_path' => ''
        ];
        try {
            $array = $excel->PutExcelStart($file, $request->param('user_login_id'));
            $data = $array['data'];//导入数据
            $error_data = $array['error_data'];//未导入数据
            $arr['success_nums'] = $array['success_nums'];//导入成功数量
            $arr['error_nums'] = $array['error_nums'];//未导入数量
            $arr['import_total'] = $array['import_total'];//导入总数
            //如果未导入数据不为空  并且 排除过表头的2行数据 还有数据的话生成未导入人才信息
            if (!empty($error_data) && count($error_data) > 2) {
                $arr['file_path'] = $excel->saveExcel($error_data, '未导入人才信息_' . date('YmdHis'));
            }

            //循环添加联系电话
            foreach ($data as $datum) {
                foreach ($datum as $k => $values) {
                    if (!$k) {
                        return ReJson(message::$ERROR_CODE, '数据表头发生错误');
                    }
                }
                $personData = $person->addPersonModel($datum);
                foreach ($datum['mobiles'] as $value) {
                    $mobileModel->addProsonMobileModel(['clue_p_id' => $personData->id, 'mobile' => $value]);
                }

                //添加人才生命周期
                $allRecord->addPersonAllocationModel($personData->id, message::$SUCC_PERSON_ADD, $request->param('user_login_id'));
            }

            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }
        return ReJson(message::$SUCC_CODE, message::$SUCC_ALL_INPORT_EXCEL, $arr);
    }

    //企业导入
    public function enterImportExcel(Request $request, Excel $excel, \app\model\ClueEnterprise $enterpriseModel, ClueMobile $mobileModel, CluePersonAllocationRecord $allRecord)
    {
        $file = $request->file('file');

        if (empty($file)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        Db::startTrans();
        $arr = [
            'import_total' => 0,
            'success_nums' => 0,
            'error_nums' => 0,
            'file_path' => ''
        ];
        try {
            $array = $excel->PutExcelStart($file, $request->param('user_login_id'));
            $data = $array['data'];
            $error_data = $array['error_data'];
            $arr['success_nums'] = $array['success_nums'];
            $arr['error_nums'] = $array['error_nums'];
            $arr['import_total'] = $array['import_total'];
            if (!empty($error_data) && count($error_data) > 2) {
                $arr['file_path'] = $excel->saveExcel($error_data, '未导入企业信息_' . date('YmdHis'));
            }
            foreach ($data as &$datum) {
                if ($datum['type'] == '注册企业') {
                    $datum['type'] = 1;
                } else {
                    $datum['type'] = 2;
                }

                $enData = $enterpriseModel->addEnterpriseModel($datum);

                foreach ($datum['mobiles'] as $value) {
                    $mobileModel->addProsonMobileModel(['clue_p_id' => $enData->id, 'mobile' => $value, 'type' => 2, 'name' => $datum['contacts']]);
                }
                //添加人才生命周期
                $allRecord->addPersonAllocationModel($enData->id, message::$SUCC_ENTER_PRISE_ADD, $request->param('user_login_id'), 2);
            }


            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return ReJson(message::$ERROR_CODE, $e->getMessage());
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_ALL_INPORT_EXCEL, $arr);
    }



    /***************************************************************************
     * 自动调回
     */
    //人才自动调回
    public function personAutoRecall(Request $request, AutoTask $autoTask)
    {
        $param = $request->post('arr');
//        unset($param['user_login_id']);
        if (!empty($param)){
            //先删除条件再新增
//            if (!empty($param[0]['clue_type']) && !empty($param[0]['task_type'])){
                $autoTask->delWhereModel (1,1);
//            }
        }
        $data = [];
        foreach ($param as $key => $value) {
//            $validate = new \app\validate\PlanTasks();
//            if (!$validate->scene ('autoWhere')->check($value)) {
//                return ReJson(message::$ERROR_CODE, $validate->getError(), []);
//            }
            if (empty($value['field'])){
                continue;
            }

            $data[$key]['field'] = $value['field'];
            if (isset($value['field2'])) {
                $data[$key]['field2'] = $value['field2'];
            }
            $data[$key]['where'] = $value['where'];
            $data[$key]['value'] = $value['value'];
            $data[$key]['clue_type'] = 1;
            $data[$key]['task_type'] = 1;

            //查询有该条件 更新  没有 新增
//            if($autoTask->getFindDataModel($data[$key])){
//                $autoTask->editFindModel ($data[$key]);
//            }else{
            $autoTask->addDataModel($data[$key]);
//            }
        }
//        $autoTask->addDataModel ($data);

        return ReJson(message::$SUCC_CODE, message::$SUCC_INSERT_DATA);
    }

    //企业自动调回
    public function enterAutoRecall(Request $request, AutoTask $autoTask)
    {
        $param = $request->post('arr');
        if (!empty($param)){
            //先删除条件再新增
//            if (!empty($param[0]['clue_type']) && !empty($param[0]['task_type'])){
                $autoTask->delWhereModel (2,1);
//            }
        }
//        unset($param['user_login_id']);
        $data = [];
        foreach ($param as $key => $value) {
//            $validate = new \app\validate\PlanTasks();
//            if (!$validate->scene ('autoWhere')->check($value)) {
//                return ReJson(message::$ERROR_CODE, $validate->getError(), []);
//            }
            if (empty($value['field'])){
                continue;
            }

            $data[$key]['field'] = $value['field'];
            if (isset($value['field2'])) {
                $data[$key]['field2'] = $value['field2'];
            }
            $data[$key]['where'] = $value['where'];
            $data[$key]['value'] = $value['value'];
            $data[$key]['clue_type'] = 2;
            $data[$key]['task_type'] = 1;

            //查询有该条件 更新  没有 新增
//            if($autoTask->getFindDataModel($data[$key])){
//                $autoTask->editFindModel ($data[$key]);
//            }else{
            $autoTask->addDataModel($data[$key]);
//            }
        }


        return ReJson(message::$SUCC_CODE, message::$SUCC_INSERT_DATA);
    }


    //人才自动调回执行
    public function personAutoRecallExe(Request $request, AutoTask $autoTask, CluePerson $person)
    {
        $data = $autoTask->getExeData($this->exePerson, $this->exeDh);

        $where = [];
        foreach ($data as $index => $datum) {
            if (!empty($datum['field2'])) {
//                $datum['field2'] = date('Y-m-d H:i:s',strtotime ($datum['field2'])+(7*60*60*24)+1);
//                $where[] = [$datum['field'],'>',$datum['field2']];
            } else {
                $where[] = [$datum['field'], $datum['where'], $datum['value']];
            }
        }

        $person->autoWhereDhExe($where);
        return ReJson(message::$SUCC_CODE, message::$SUCC_INSERT_DATA);
    }



    /*************************************************************自动回收***********************************/

    //人才自动回收
    public function personRecovery(Request $request, AutoTask $autoTask)
    {
        $param = $request->post('arr');
        $data = [];

        if (!empty($param)){
            //先删除条件再新增
//            if (!empty($param[0]['clue_type']) && !empty($param[0]['task_type'])){
                $autoTask->delWhereModel (1,2);
//            }
        }
        foreach ($param as $key => $value) {

//            $validate = new \app\validate\PlanTasks();
//            if (!$validate->scene ('autoWhere')->check($value)) {
//                return ReJson(message::$ERROR_CODE, $validate->getError(), []);
//            }
            if (empty($value['field'])){
                continue;
            }

            $data[$key]['field'] = $value['field'];
            if (isset($value['field2'])) {
                $data[$key]['field2'] = $value['field2'];
            }
            $data[$key]['where'] = $value['where'];
            $data[$key]['value'] = $value['value'];
            $data[$key]['clue_type'] = 1;
            $data[$key]['task_type'] = 2;

            //查询有该条件 更新  没有 新增
//            if($autoTask->getFindDataModel($data[$key])){
//                $autoTask->editFindModel ($data[$key]);
//            }else{
            $autoTask->addDataModel($data[$key]);
//            }
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_INSERT_DATA);
    }

    //企业自动回收
    public function enterRecovery(Request $request, AutoTask $autoTask)
    {
        $param = $request->post('arr');

        if (!empty($param)){
            //先删除条件再新增
//            if (!empty($param[0]['clue_type']) && !empty($param[0]['task_type'])){
                $autoTask->delWhereModel (2,2);
//            }
        }

        $data = [];
        foreach ($param as $key => $value) {

//            $validate = new \app\validate\PlanTasks();
//            if (!$validate->scene ('autoWhere')->check($value)) {
//                return ReJson(message::$ERROR_CODE, $validate->getError(), []);
//            }

            if (empty($value['field'])){
                continue;
            }

            $data[$key]['field'] = $value['field'];
            if (isset($value['field2'])) {
                $data[$key]['field2'] = $value['field2'];
            }
            $data[$key]['where'] = $value['where'];
            $data[$key]['value'] = $value['value'];
            $data[$key]['clue_type'] = 2;
            $data[$key]['task_type'] = 2;

            //查询有该条件 更新  没有 新增
//            if($autoTask->getFindDataModel($data[$key])){
//                $autoTask->editFindModel ($data[$key]);
//            }else{
            $autoTask->addDataModel($data[$key]);
//            }
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_INSERT_DATA);
    }

    //查看自动执行条件
    public function getAutoWhereData(Request $request, AutoTask $autoTask)
    {
        $param = $request->get();

        if (empty($param['clue_type']) || empty($param['task_type'])) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        $result = $autoTask->getExeData($param['clue_type'], $param['task_type']);

        $data = [];
        for ($i = 0, $iMax = count($result); $i < $iMax; $i++) {
            if (!empty($result[$i]['field2'])) {
                $data['header'][] = $result[$i];
            } else {
                $data['foot'][] = $result[$i];
            }
        }
        return ReJson(message::$SUCC_CODE, message::$SUCC_SELECT_DATA, $data);
    }



    /**************************************************************************************************************************************
     * 表单定时提醒
     */
    //添加定时提醒
    public function addFromRemind(
        Request                $request,
        \app\model\UserMessage $message,
        FinanceServer          $financeServer,
        RedisService           $redisService,
        OrderPersonCertificateRegister     $OrderPersonCertificateRegister,
        SystemOperateLog $systemOperateLog
    )
    {
        $param = $request->post();
        $uid = $request->post ('user_login_id');

        if (empty($param['content']) || empty($param['uid']) || empty($param['execution_date']) || empty($param['certificate_code'])) {
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }

        //查询订单编号属于哪类订单
        $type = $financeServer->getCertificateType($param['certificate_code']);

        $message->addInformationModel(
            $param['content'],
            $param['uid'],
            $uid,
            $param['execution_date'],
            2,
            $param['certificate_code'],
            $param['order_company_id']
        );
        $title = '';
        switch ($type){
            case 1: //企业证书
                $title = "公司证书";
                break;
            case 2://倒证
                $title = "倒证";
                break;
            case 3://证书办理
                $title = "证书办理";
                break;
            case 4://企业证书
                $title = "企业证书";
                break;
            case 99://证书审核
                $title = "证书审核";
                $redisService->updateOrderZsshData ($param['order_company_id']);
                break;
        }

        //添加表单定时器
        $systemOperateLog->addOperate($uid, message::$ORDER, "添加定时提醒".$title.':'.$param['certificate_code']);

        return ReJson(message::$SUCC_CODE, message::$SUCC_OPERATE);
    }


    //获取表单定时器内容
    public function getRemindContent(Request $request, \app\model\UserMessage $message)
    {
        $param = $request->get();

        if (empty($param['certificate_code']) || empty($param['id'])) {
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }

        $result = $message->getFromRemindModel($param['id'], $param['certificate_code']);

        return ReJson(message::$SUCC_CODE, message::$SUCC_SELECT_DATA, $result);
    }

    //注册企业名称模糊搜索
    public function getRegEnterPriseLikeSearch(Request $request, UnitInfo $info,\app\model\ClueEnterprise $enterpriseModel)
    {
        $name = $request->get('name');

        if (empty($name)) return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);

        $result = $info->getLikeName($name);
        //查询线索库企业库
        $result2 = $enterpriseModel->getLikeNameModel($name);
        $data = array_merge ($result,$result2);
        $data2 = [];
        foreach ($data as $datum) {
            $title = array_column ($data2,'title');
            if(!in_array ($datum['title'],$title)){
                $data2[] = $datum;
            }
        }

        return ReJson(message::$SUCC_CODE, message::$SUCC_SELECT_DATA, $data2);
    }


    //企业证书注册公司需求点击排队
    public function enterpriseCertRegistrationQueue(Request $request, OrderEnterpriseCertificateRegister $orderEnterpriseCertificateRegister)
    {
        $id = $request->post('id');
        if (!$id) {
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }
        $status = $orderEnterpriseCertificateRegister::GS_STATUS_TWO;
        $orderEnterpriseCertificateRegister->gsStatusEdit($id, $status);
        return ReJson(message::$SUCC_CODE, message::$SUCC_OPERATE);
    }

    //企业证书注册公司需求点击退单
    public function enterpriseCertRegistrationBack(Request $request, OrderEnterpriseCertificateRegister $orderEnterpriseCertificateRegister)
    {
        $id = $request->post('id');
        if (!$id) {
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }
        $status = $orderEnterpriseCertificateRegister::GS_STATUS_THREE;
        $orderEnterpriseCertificateRegister->gsStatusEdit($id, $status);
        return ReJson(message::$SUCC_CODE, message::$SUCC_OPERATE);
    }

    /**
     * 下载文件重命名
     */
    public function downLoadFile(Request $request,OrderTransactionRecord $transactionRecordModel)
    {
        $id = $request->param ('id');
        if (empty($id)) return ReJson (message::$ERROR_CODE,message::$ERR_PARAM_EMPTY);

        $data = $transactionRecordModel->getIdDataModel($id);
        $file_url = $data['annex'];
        $out_filename = $data['annex_name'];

        $file = @fopen($file_url, "r");

        $content="";
        while(!feof($file)){//测试文件指针是否到了文件结束的位置
            $data=fread($file,1024);
            $content.=$data;
        }
        fclose($file);
        $filesize = strlen($content);
        header('Accept-Ranges: bytes');
        header('Accept-Length: ' . $filesize);
        header('Content-Transfer-Encoding: binary');
        header('Content-type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . $out_filename);
        header('Content-Type: application/octet-stream; name=' . $out_filename);
        echo $content;
        die();
    }

    public function handlePersonIds($uid_person_ids, $person_ids, $flag)
    {
        //chern添加数组重新索引
        $person_ids = array_values($person_ids);
        if ($uid_person_ids && !$person_ids) {
            $person_ids = $uid_person_ids;
        } elseif (!$uid_person_ids && $person_ids) {
            $person_ids = $uid_person_ids;
        } elseif ($uid_person_ids && $person_ids) {
            if (count($person_ids) == 1 && $person_ids[0] == 0 && !$flag) {
                $person_ids = $uid_person_ids;
            } else {
                $person_ids = array_intersect($person_ids, $uid_person_ids);
            }

        }
        return $person_ids;
    }

    /**
     * 证书注册-公司证书-订单生成
     */
    public function companyOrderCreate(
        Request                $request,
        OrderEnterpriseCompany $enterpriseCompanyModel,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel,
        OrderDeal $orderDeal,
        OrderLog $orderLog,
        \app\service\Order $orderSer,
        Gateway $gateway,
        \app\service\User $userService,
        User $userModel,
        CluePerson $personModel
    ){
        $uid = $request->post ('user_login_id');
        $param = $request->post();

        $id = $param['id'];
        $certificateCode = $param['certificate_code'];

        if (empty($id) || empty($certificateCode)){
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }
        $sale_date = date('Y-m-d H:i:s');

        //获取订单信息
        $orderData = $enterpriseCompanyModel->getWhereIdOrderByCreateData ($id);
        /**
         * 修改订单状态为已售出
         */
        $enterpriseCompanyModel->updateStatus($certificateCode,$sale_date);
        //删除业绩总表缓存
        $redisService->delPerformance ($orderData);
        //删除订单缓存
        $redisService->delOrderDzData ($orderData,'order_gszs');
        //删除人才库ID缓存
        $redisService->delPersonData ($personModel->getPersonIdCardInfo ($orderData['person_id_card'])['id']);
        //记录系统日志
        $systemOperateLogModel->addOperate ($uid,message::$ORDER,'公司证书-售出订单：'.$certificateCode);
        //记录订单日志
        $orderLog->addDataModel ([
            'submit_id' => $uid,
            'message' => message::$ORDER_ENPER_DZ_CJ,
            'certificate_code' => $certificateCode,
            'order_company_id' => $id
        ]);
        //添加成交记录
        $orderDeal->addOrderDataModel ([
            'order_company_id'=>$id,
            'certificate_code'=>$certificateCode,
            'status'=>$orderSer->getOrderStatus ($id,$certificateCode)
        ]);

        //发送全局成交信息
        $gateway->sendToAll(json_encode([
            'type'=>'deal',
            'content'=>$userService->getUidOrgTitle ($orderData['submit_id']),
            'nickname'=>$userModel->getIdNickName($orderData['submit_id']),
            'title'=> date('Y-m-d H:i:s')."成交了公司证书！"
        ]));

        return ReJson (message::$SUCC_CODE,message::$ORDER_DEAL);
    }

    /**
     * 证书注册-公司证书-证书注册完成
     */
    public function companyRegComplete(
        Request                $request,
        OrderEnterpriseCompany $enterpriseCompanyModel,
        RedisService $redisService,
        SystemOperateLog $systemOperateLogModel,
        OrderDeal $orderDeal,
        OrderLog $orderLog,
        \app\service\Order $orderSer
    ){
        $uid = $request->post ('user_login_id');
        $param = $request->post();

        $id = $param['id'];
        $certificateCode = $param['certificate_code'];

        if (empty($id) || empty($certificateCode)){
            return ReJson(message::$ERROR_CODE, message::$ERR_PARAM_EMPTY);
        }

        $orderData = $enterpriseCompanyModel->getWhereIdOrderByCreateData ($id);

        /**
         * 判断订单状态是否为已售出
         */
        if ($orderData['status']['id'] == 1){
            $enterpriseCompanyModel->certificateRegModel($id);
            //删除订单缓存
            $redisService->delOrderDzData ($orderData,'order_gszs');
            //记录系统日志
            $systemOperateLogModel->addOperate ($uid,message::$ORDER,'公司证书-证书注册完成：'.$certificateCode);
            //记录订单日志
            $orderLog->addDataModel ([
                'submit_id' => $uid,
                'message' => message::$ORDER_CERTIFICATE_REG_DEAL,
                'certificate_code' => $certificateCode,
                'order_company_id' => $id
            ]);
            return ReJson (message::$SUCC_CODE,message::$ORDER_CERTIFICATE_REG_DEAL);
        }

        return ReJson (message::$ERROR_CODE,message::$ORDER_CERTIFICATE_REG_DEAL_ERR);

    }
}